0

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?

Daniel Jørgensen
  • 1,183
  • 2
  • 19
  • 42
  • Could it be a timeout when running `rc.local`? Have you tried spawning on the background? (not delay boot also): `php '/var/www/html/cron/bootup.php' &` – urban May 03 '16 at 20:01
  • Is there a specified max execution time for rc.local or so ? – Daniel Jørgensen May 03 '16 at 20:08
  • Don't know to be honest... but no logs or errors make me think that something/one killed the process... do you need it synchronous? – urban May 03 '16 at 20:09
  • I've just added the `&` char after script line like you said, and it seems to be working actually.. It doesnt time out anymore and continues the download! The & char tells the system to run the script in background i assume ? – Daniel Jørgensen May 03 '16 at 20:12
  • yes it forks. If you are quick enough, after booting do a `ps -ef | grep php` and you should see it. – urban May 03 '16 at 20:15
  • Maybe i was too quick there.. The third time i tried it halted half way through the download. I dont get it. Why does it work sometimes and other times not. It makes no sense – Daniel Jørgensen May 03 '16 at 20:22

0 Answers0