SteveMilner
Posts: 13
Joined: Mon Jul 14, 2014 7:55 pm

Problem Executing Code at Startup

Fri May 22, 2015 4:36 pm

Hi.

This is staring to do my head in!

Code: Select all

uname -a:
Linux raspbmc 3.10.36 #4 PREEMPT Sun Apr 13 21:25:32 UTC 2014 armv6l GNU/Linux
Up until recently I have had some script entries in rc.local which worked fine, they no longer seem to be working now - I had an old raspbmc from June last year that I upgraded late April this year, which I think caused the rc.local to no longer be executed

Code: Select all

#!/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.

# Log start of script
logger -s "`date` Starting rc.local"

#Monitor the UPiS for running on battery and shutdown as required
logger -s "`date` Start Monitoring UPiS"
/home/pi/bin/shutdown-after-power-loss.sh &

#Monitor the shutdown button on the UPiS
#sudo python /home/pi/bin/fwshut.py.

#Use UPiS to set clock - FIXME
#logger -s "`date` Setting Clock"
#echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device.
#hwclock -s

# This may be needed by minidlna to get inotify to work properly
logger -s "`date` Setup inotify node"
mknod /dev/inotify c 10 63

#Not sure if minidlna starts correctly uncomment below to force
logger -s "`date` delay 60s start minidlna"
sleep 60 && sudo service minidlna start

logger -s "`date` Ending rc.local"
exit 0
Now, at boot none of the entries are written to /var/log/messages and none of the actions expected have happened - no minidlna, no /dev/inotify and the shutdown scrip doesn't run.

After boot, and using ssh to obtain a terminal it is possible to start rc.local correctly using

Code: Select all

sudo service rc.local start
I read somewhere that upstart may be causing the rc.local to start too early so I decided to move to an upstart script (I have little experience with upstart but found a recipe elsewhere, commented out all the lines in rc.local and created /etc/init/my-jobs.conf:

Code: Select all

#
#/etc/init/my-jobs.conf
#

description     "Replacement Slot for rc.local"

start on local-filesystems

script
#Just wait a little while to be sure
sleep 10

# Log start of script
logger -s "`date` Starting my-job"

#Monitor the UPiS for running on battery and shutdown as required
logger -s "`date` Start Monitoring UPiS"
/home/pi/bin/shutdown-after-power-loss.sh &

#Monitor the shutdown button on the UPiS
#sudo python /home/pi/bin/fwshut.py.

#Use UPiS to set clock - FIXME
#logger -s "`date` Setting Clock"
#echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device.
#hwclock -s

# This may be needed by minidlna to get inotify to work properly
logger -s "`date` Setup inotify node"
mknod /dev/inotify c 10 63

#Not sure if minidlna starts correctly uncomment below to force
logger -s "`date` delay 60s start minidlna"
sleep 60 && sudo service minidlna start

logger -s "`date` Ending my-job"

end script
Starting manual using:

Code: Select all

start my-jobs
works fine, with all the expected results.

It does not however appear to start after a reboot

I put in the sleep 10 to make sure the logging service was running, but I am currently stumped how to get either rc.local or the uspstart script to work at boot.

Any suggestions gratefully received.

Regards,
Steve

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Problem Executing Code at Startup

Fri May 22, 2015 5:25 pm

Try using crontab. See if that works.
There are 10 types of people: those who understand binary and those who don't.

SteveMilner
Posts: 13
Joined: Mon Jul 14, 2014 7:55 pm

Re: Problem Executing Code at Startup

Fri May 22, 2015 5:37 pm

I have this working now, but I have no idea why.

Changed the upstart conf file start to:

Code: Select all

start on runlevel [2345]
stop on runlevel [016]
And moved my script (shutdown one)

to

Code: Select all

/usr/bin/
All working now!
Steve

Return to “Troubleshooting”