I have a python daemon process that gets started via rc.local. This same script, with the same permissions, is installed on a few other Ubuntu boxes I have. It runs without trouble on those installations. That is, after restarting the box, the daemon process is running.
With this particular installation though, the daemon process is not running by the time I log in and check for the existence of the process. The rc.local files between systems are identical (or at least close enough):
localaccount@sosms:~$ cat /etc/rc.local
#!/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.
python /var/www/myDaemon/Main.py > /var/log/somelog.txt
exit 0
The permissions are:
localaccount@sosms:~$ ls -la /etc/rc.local
-rwxr-xr-x 1 localaccount localaccount 370 Jun 3 11:04 rc.local
I tested if the rc.local process is getting executed by using this test rc.local:
localaccount@sosms:/var/log/sosmsd$ cat /etc/rc.local
#!/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.
echo "test" > /home/localaccount/test1
/usr/bin/python /var/www/sosms/sosmsd/Main.py > /var/log/sosmsd/log/log
echo "test" > /home/localaccount/test2
exit 0
localaccount@sosms:/var/log/sosmsd$
And only the first test file (test1) gets created after restarting the box. I'm guessing it means that the python line is causing some kind of issue, but I get no output in /var/log/sosmsd/log/log:
localaccount@sosms:~$ ls
test1
Update:
I then followed larsks' advice and determined that I was getting this error from launching the python script:
mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
Does this mean that rc.local is being executed before MySQL has had a chance to be initialized? Where do I go from here?
You should create an init script /etc/init.d/mydaemon
for your daemon from available skeleton.
Then you will be able to set its startup order so that MySQL is already available.
Here is a good starting point.