LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-14-2014, 12:11 PM   #1
linuxecho
LQ Newbie
 
Registered: Feb 2014
Posts: 8

Rep: Reputation: Disabled
why init script cannot source init tools unless session root


I’m trying to set up a daemon. I’m keen on using the lsb standard functions to ensure lsb compliance if at all possible. The init-script itself is called ‘websites_send_backups’ is in /etc/init.d and is 755 –
-rwxr-xr-x 1 root root 2690 Feb 13 18:53 websites_send_backups
My problem is when I run ‘sudo /etc/init.d/websites_send_backups start’ as the user deploy, I consistently get the message /etc/init.d/websites_send_backups: 14: .: Can't open /lib/lsb/init-functions’ and nothing besides. Line 14 of the file in question is:
. /lib/lsb/init-functions
(with a space between the dot and the first slash – which I believe should be equivalent to writing ‘source /lib/lsb/init-functions’).
I can confirm the file is there, is 751 and is not empty. ls-l /lib/lsb/init-functions gives:
-rwxr-x--x 1 root root 11445 Jun 5 2013 /lib/lsb/init-functions
ls –l /lib/ shows that the lsb folder itself is 755:
drwxr-xr-x 3 root root 4096 Feb 13 17:09 lsb
When I run the exact same line in the shell as deploy (. /lib/lsb/init-functions) I get no complaint so presumably there is no issue finding it or issue with deploy's permissions which are certainly sufficient.
I can also read the init-functions file using vim as the user deploy.
I could perhaps understand this happening if the line was . ./lib/lsb/init-functions (with the extra dot as that would be sourcing it relative to the ‘current’ directory or certainly if it was . ~/lib/lsb/init-functions, sourcing it relative to the invoker’s home directory) but I can’t understand why it would fail to find it when the path is absolute. Whatever it is that interprets the init file, surely it recognises an absolute path?
For want of anything better to do I have played with the path and the permissions but got no light from that.
Can anyone suggest why the init-functions cannot be sourced by the line ‘. /lib/lsb/init-functions’ unless the session is root? I imagine I’m missing fundamental about how this all works...
sorry I appreciate that the title includes the words 'unless session root' but I've just realised that the error I get when running it as root (which I was going to post separately if I couldn't solve it) is related...-
when I run the init script as root I get the message:
':No such file or directoryackups: line 13: /lib/lsb/init-functions
: numeric argument requiredackups: line 22: exit 5'
Regarding line 22 perhaps I should re post under a separate q if addressing this issue doesn't solve that one. Regarding the no such file, as mentioned above I'm sure thats not the case. As an aside, is it normal that the first part of the message has stuck 'ackups' which is presumably part of the 'website_send_backups' file name in there? Does that indicate an issue with the script or is it normal truncation?

Last edited by linuxecho; 02-14-2014 at 04:40 PM. Reason: pasted wrong error- thanks to rigor for pointing that out
 
Old 02-14-2014, 03:59 PM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
Hi linuxecho,

My init-functions file is mode 755 and if I make it 751, then when I try to execute it as a non-root User, I get Permission denied. I don't get Can't open, but I do still wonder about the permissions of your init-functions file.

Last edited by rigor; 02-14-2014 at 05:17 PM. Reason: Edited in response to edit by OP of initial post.
 
Old 02-14-2014, 04:35 PM   #3
linuxecho
LQ Newbie
 
Registered: Feb 2014
Posts: 8

Original Poster
Rep: Reputation: Disabled
Sorry -amazing that I read over my post and didn't see that. Stupidly, the actual error I posted was taken from a trial after I had been messing with the path to see what happened. Previously I had the error '14: .: can't open file /lib/lsb/init-functions and after posting I put the line back and still had the same issue. Sorry for confusion, do you mind if I edit it so it doesn't confuse others?

Yes I figured it was more likely because it couldn't locate the file, because I got the same error if calling a random path I knew didn't exist but not being absolutely sure I wanted to show I'd more or less ruled out a permissions issue.

Re symbolic links I don't think so. The init script I mention is a straight forward file located in /etc/init.d and I'm pretty sure the init functions file isn't a link. The daemon that it calls isn't a link either but I think that's downstream of this issue. What confused me is that because the path used for the sourcing was absolute, where its actually being invoked from shouldn't matter? Really appreciative of your input so far.

Last edited by linuxecho; 02-14-2014 at 04:54 PM. Reason: clarification
 
Old 02-14-2014, 05:21 PM   #4
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
linuxecho,

OK, well I edited my response to your edited initial post, since your edit largely seems to invalidate my original response. But you might want to try mode 755 for your init-functions file. Also, if you add "set -x" as the first line in your script, does it give you a better idea what the script is trying to do?
 
1 members found this post helpful.
Old 02-15-2014, 03:15 AM   #5
linuxecho
LQ Newbie
 
Registered: Feb 2014
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hi rigor,

I made a bit of a 'comedy of errors' of this post didn't I? Even the subject is now a misleading - I did try playing with path and the permissions previously as I said and that included making the init-functions 755, I guess i should have been more specific. Also, as noted above, even running it as root I get an error that suggests the file can't be found. As soon as I next get access to the machine, either later today or failing that, Monday, ill add set-x first thing and update this thread. Like I said, sorry for the confusion and thanks for your help.
 
Old 02-17-2014, 04:18 AM   #6
linuxecho
LQ Newbie
 
Registered: Feb 2014
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hi rigor,

Solved!

This morning I tried adding the line "set -x" as the first line of the script and got "set: Illegal option -".

By this stage I had decided that it must be to do with whatever was running the script not being properly configured or something (I was wrong) and I thought that corroborated that idea so I tried setting #!/bin/sh as the first line so I know what's running it, - but I got the error /bin/sh^M: bad interpreter: No such file or directory. Aha- I thought, there's an error that I can probably get somewhere with. Sure enough I got back that the file was formatted incorrectly - the ^M is the clue, its formatted as DOS. Fair enough - I had copied the script off the web to an ftp location, curled it using the commandline to the /etc/init.d/ folder and then edited it using vim to include all the details I required.

Once I'd reformatted it as unix (:set fileformat=unix in vim) it worked perfectly. Your suggestion therefore did set me directly on the road to a solution - thanks for your help and patience. I will have marked your post as helpful by the time you read this.

I feel this issue was a tricky one because the original error re 'can't open', with no whiff of a "^M", gave no hint as to the real issue.

The scope of the problem seemed so basic that it was really getting to me on Friday. Today I was a bit calmer which helped. On the plus side, although its a long, hard way to learn a simple, short lesson - after that level of frustration I can be certain I won't be making it again
 
Old 02-17-2014, 04:11 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,364

Rep: Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752Reputation: 2752
2 recommendations:

1. write scripts on Linux - simple/easy/correct
2. if you must copy from another OS eg MS, use dos2unix cmd as soon as you've txfrd it
(on my system that's /usr/bin/dos2unix )
 
1 members found this post helpful.
Old 02-17-2014, 05:03 PM   #8
linuxecho
LQ Newbie
 
Registered: Feb 2014
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hi Chris,

Thanks for the heads up. At work I'm on a windows machine (which I don't think is set to change for infrastructure reasons and because our main products are still windows based) and although I'm beginning to work on some linux based servers we have there I'm trying to ensure I do everything on a series of VM's I keep on my local machine first - I prefer to make my mistakes in that playground environment and I often end up transferring stuff one way or the other, so I'll be using that.

At home I'm about to take the plunge and have decided to switch my entire IT infrastructure - a laptop and a desktop - over to linux. I like the fact you can easily get hands on with linux. And it will be like having a new computer. However it took me an afternoon just to read about various distributions and desktop environments etc. Many people suggest experimentation but with limited time and energy one isn't going to do that entirely randomly. At the minute I'm leaning toward KDE for the laptop (so I can get all tweaky) and with a bit more pizzaz for the desktop so my wife is impressed and doesn't flip out - perhaps Cinammon. Why I mention this circumstance I don't know. But chalk one more up for linux - another fan boy is being born.

Last edited by linuxecho; 02-17-2014 at 05:14 PM.
 
Old 02-17-2014, 05:17 PM   #9
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
Hi linuxecho,

If you're going to have to copy things from MS-Win to Linux or Unix, you might want to consider using set list in vim, as it will show you any ^M an some other "funny" chars that might be there.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Init script in /etc/init.d does not start at boot tdnnash25 Linux - Server 4 12-18-2009 04:40 PM
module-init-tools, initramfs-tools broken virgilhowardson Debian 1 03-08-2009 12:30 AM
source for init (/sbin/init) ashok449 Linux - Kernel 2 03-02-2008 04:20 PM
error in init script of mysql from source packets Linux - Software 3 02-15-2008 01:53 AM
Starting a daemon in an init.d bootup script without root being the owner BobTheSlob Linux - General 1 09-19-2007 11:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration