Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a service that I install as so:

install -m 755 init_script /etc/init.d/spacenavd
cd /etc/rc2.d
ln -s ../init.d/spacenavd S99spacenavd

what the init_script does is start the script:

/usr/local/bin/spacenavd -v

All of this works fine and allows the service to start automatically on startup. However I am having trouble running another script on startup that uses the spacenavd service. This script works normally when I run it manually after login in. However, running it on startup on as so doesn't work when I put it in rc.local.

I do the following in rc.local:

cd /home/filedirec
sudo ./my_script &

This works sometimes and sometimes doesn't. I can't seem to determine what the cause is. Whats a good way to trouble shoot?

share|improve this question
    
I don't know about spacenavd, but is it possible that it returns and allows init to continue before it's ready to accept connections? Perhaps sometimes rc.local is getting run before spacenavd is fully functional. Try adding a sleep 10 at the top of rc.local and see if the problem persists. Dunno that it's a proper fix, but it should help you troubleshoot –  jerm Oct 2 '13 at 4:06
    
Debian has been moving to a dependency-based init setup. Not sure of the exact details off the top of my head. –  Shadur Oct 2 '13 at 7:59
1  
... More importantly, I just checked and rc.local gets run at S22. So you're launching the script well before the server it needs can be reasonably expected to be running. –  Shadur Oct 2 '13 at 8:00
    
@Shadur so I should set spacenavd to something lower than S22? –  mugetsu Oct 2 '13 at 17:06
    
Sounds like a plan. –  Shadur Oct 2 '13 at 21:33

1 Answer 1

Deja Vu.

Sudo is an interactive program requiring you to provide a password in order to run a command as root (or another user) if you have not recently put in your credentials. The rc.local script is not attached to your console, so you never see it asking for the password.

The rc.local script is also already running as root, so you should remove the sudo command from it.

Better still would be to simply replace all you added with: /home/filedirec/my_script (or /home/filedirec/my_script & if need be). Using the absolute path will make it faster and easier to see exactly what the rc.local script is doing if it needs to be reviewed later, cd and the like are generally better suited to interactive shells.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.