Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a single command in my /etc/rc.local script that is supposed to start the update daemon for Tiny Tiny RSS during startup, but the script is not executed during startup. Why?

The entire /etc/rc.local file:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

/sbin/start-stop-daemon -b -c www-data:www-data -S -x /usr/bin/php /var/www/ttrss/update_daemon2.php -- -quiet

exit 0

/etc/rc.local is executable:

# ls -l /etc/rc.local
-rwxr-xr-x 1 root root 342 May 25 16:14 /etc/rc.local

/etc/init.d/rc.local exists and is executable:

# ls -l /etc/init.d/rc.local
-rwxr-xr-x 1 root root 801 Jul 27  2012 /etc/init.d/rc.local

/etc/init.d/rc.local is supposed to be executed at startup for this runlevel:

# runlevel 
N 2
# ls -l /etc/rc2.d/S99rc.local 
lrwxrwxrwx 1 root root 18 Sep 22  2012 /etc/rc2.d/S99rc.local -> ../init.d/rc.local

If I manually call /etc/rc.local from the command line the update_daemon loads...

# /etc/rc.local
# ps ax | grep update_daemon2.php
2233 ?        S      0:00 /usr/bin/php /media/sda5/www/news/update_daemon2.php -quiet
2234 ?        S      0:00 /usr/bin/php /media/sda5/www/news/update_daemon2.php -quiet

... which I have to remember to do every time my server restarts until this problem is fixed.

Similar questions already exist, but so far I've been unable to apply the information within to my specific problem.

Why is the command in rc.local not executed during startup?

share|improve this question

3 Answers 3

rc.local script exits if any error occurred while executing any of it's commands (mention the -e flag in #!/bin/sh -e).

It is possible that some prerequisites are not met when you try to run your commands when rc.local execution takes place, so your command execution fails.

I encountered the same thing while manually setting cpu governor and failing to do so in rc.local. Here's my custom workaround, which uses update-rc.d to make your commands run on startup:

  1. Create a file myscript.sh in directory /etc/init.d with a heading: #!/bin/sh
  2. Put your custom commands as a content
  3. Make executable: sudo chmod +x /etc/init.d/myscript.sh
  4. Create symlinks for your script for various runlevels: sudo update-rc.d myscript.sh defaults

Also, you could check /etc/network/if-up.d scripts and see if you could trigger your commands when networking starts.

share|improve this answer
    
Thank you for the answer. My setup has changed since I posted the question, so I am unable to test if your answer would have solved the problem. –  DrTwox Mar 9 at 8:24

try sudo sysv-rc-conf and check out if rc.local is enabled

rc.local         [ ]   [x]   [x]   [x]   [x]   [ ]   [ ]   [ ]
share|improve this answer
    
Yes, it is enabled. –  DrTwox May 25 '13 at 23:54

We had this problem on some hosted servers loading FW rules.

On these boxes they reboot VERY quickly and we found just putting a "sleep 1" in rc.local before the load statements seems to fix the issue. I guess it gave a little time for the interfaces to settle before loading the FW rules.

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.