I have a script that I need to be run once the system boots up. I have therefore placed the script inside my /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.
screen -dmS PythonLoader /usr/bin/python2.7 /var/www/html/scripts/load.py
php '/var/www/html/cron/bootup.php'
exit 0
Inside my /var/www/html/cron/bootup.php
file I have the following code, which downloads a file from a remote host
$head = array_change_key_case(get_headers($url, TRUE));
$remoteFileSize = $head['content-length'];
echo (file_put_contents($this->serverZipLocation . basename($url), fopen($url, 'r')) == $remoteFileSize) ? true : false;
My problem is that the above code only downloads around 60% of the remote file, where after it just stops script execution. Looking at my /var/log/lighttpd/error.log
yields nothing other than a message about the server being started.
If I however run the script manually by just loging into a terminal as root and write /etc/rc.local
there is no problems at all.
For convenience the /var/www/html/scripts/load.py
which is also loaded inside the /etc/rc.local
file has no problems.
Why doesn't this work?
EDIT: I've tried now to put a sleep 120
just before the first line in rc.local
, and this seems to make it work. It could seem that something required isn't ready when the scripts are run? Maybe network?