Page 1 of 1
Service wont Start on Boot
Posted: Mon Sep 07, 2015 5:57 am
by hp1975
I've successfully got my Pi running as an internet radio using an Adafruit LCD display. The one bit i cant get working is getting the 'radio' service to start when the pi boots. I have tried putting the file that starts the serivce in /etc/init.d as well as placing an extra line at the end of the /etc/rc.local file as well. Neither seems to work. When i power cycle the Pi I still have to type:
to get the radio.py script to run.
The radio service file code is:
Code: Select all
### BEGIN INIT INFO
# Provides: Radio / LCD date / time / ip address
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Controll MPD
# Description: Radio / LCD date / time / ip address
### END INIT INFO
#! /bin/sh
# /etc/init.d/radio
DAEMON='/home/pi/radio/radio.py 2>&1'
PIDFILE=/var/run/radio.pid
export HOME
case "$1" in
start)
echo "Starting Radio"
start-stop-daemon --start --make-pidfile --pidfile $PIDFILE --exec $DAEMON -b
;;
stop)
echo "Stopping Radio"
start-stop-daemon --stop --pidfile $PIDFILE --retry 5
;;
*)
echo "Usage: /etc/init.d/radio {start|stop}"
exit 1
Grateful for any assistance.
Re: Service wont Start on Boot
Posted: Mon Sep 07, 2015 6:49 am
by KLL
the start looks wrong, for a python source need to run it via python
for python 2 use python, for python3 use python3, for GPIO.. used sudo
DAEMON='/usr/bin/python /home/pi/radio/radio.py'
Re: Service wont Start on Boot
Posted: Mon Sep 07, 2015 8:05 am
by hp1975
Hey thanks for the quick reply. I'll give that a try. I dont understand your final comment
for python 2 use python, for python3 use python3, for GPIO.. used sudo
Can you explain this a bit more?
cheers
Re: Service wont Start on Boot
Posted: Mon Sep 07, 2015 8:35 am
by RaTTuS
the service should be in /etc/init.d
and links in the other folders
see
update-rc.d
[ man update-rc.d ]
Re: Service wont Start on Boot
Posted: Mon Sep 07, 2015 11:49 am
by hp1975
I have already run update-rc.d and I assumed it worked. I did receive some insserv errors about another service but I understand you can ignore those anyway. I assume if I check /etc/rc0.d through /etc/rc6.d i should see the links?
Re: Service wont Start on Boot
Posted: Mon Sep 07, 2015 8:39 pm
by hp1975
ok tried a couple more things and still no autorun. The script now looks like this:
Code: Select all
### BEGIN INIT INFO
# Provides: Radio / LCD date / time / ip address
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Controll MPD
# Description: Radio / LCD date / time / ip address
### END INIT INFO
#! /bin/sh
# /etc/init.d/radio
DAEMON='/usr/bin/python /home/pi/radio/radio.py 2>&1 &'
PIDFILE=/var/run/radio.pid
USER=root
export HOME
case "$1" in
start)
echo "Starting Radio"
start-stop-daemon --start --background --oknodo --pidfile $PIDFILE --make-pidfile --user $USER --chuid $USER --startas $DAEMON
stop)
echo "Stopping Radio"
start-stop-daemon --stop --pidfile $PIDFILE --retry 5
;;
*)
echo "Usage: /etc/init.d/radio {start|stop}"
exit 1
Added some 'arguments'(?) to start-stop-daemon and also added the location of python as suggested. Also ran update-rc.d again to be sure. It still doesnt start on reboot but will start fine if a start it manually as a service.
This page was useful
http://blog.scphillips.com/posts/2013/0 ... e-on-boot/ and helped me understand a little of what the script is doing. No luck though!
Anything else I can try or check?
ta
Re: Service wont Start on Boot
Posted: Tue Sep 08, 2015 3:51 am
by KLL
this works:
sudo nano /etc/init.d/radio
Code: Select all
#!/bin/sh
### BEGIN INIT INFO
# Provides: MY PYTHON SERVICE
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: python data stream auto start
# Description: start pyton service ...
### END INIT INFO
MYNAME='/etc/init.d/radio'
DAEMON_NAME='radio'
# use python 2... symlink
DAEMON='/usr/bin/python /home/pi/radio/'$DAEMON_NAME'.py'
#DAEMON_OPTS=''
DAEMON_USER='root'
PIDFILE='/run/'$DAEMON_NAME'.pid'
. /lib/lsb/init-functions
do_start () {
log_daemon_msg 'Starting system '$DAEMON_NAME
start-stop-daemon --start --oknodo --background --pidfile $PIDFILE --make-pidfile --name $DAEMON_NAME --user $DAEMON_USER --exec $DAEMON
log_end_msg $?
}
do_stop () {
log_daemon_msg 'Stopping system '$DAEMON_NAME
start-stop-daemon --stop --oknodo --quiet --pidfile $PIDFILE --retry 30 --exec $DAEMON
log_end_msg $?
}
case "$1" in
start|stop)
do_${1}
;;
restart|reload|force-reload)
do_stop
do_start
;;
status)
status_of_proc -p "$PIDFILE" "$DAEMON" $DAEMON_NAME && exit 0 || exit $?
;;
*)
echo "Usage: $MYNAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
sudo chmod 755 /etc/init.d/radio
sudo update-rc.d radio defaults
Re: Service wont Start on Boot
Posted: Tue Sep 08, 2015 5:37 pm
by hp1975
@KLL thanks for the helpful response. Ive replaced my radio service script with the one you have provided. It starts manually
sudo service radio start
But....... it still doesnt autostart when I reboot. All of the links appear in the /etc/rc0.d directories.
Is there any way to diagnose how far through the boot sequence it is getting before it fails to start the service? Is there any way to tell if the script was actually started (and then stopped?) sorry , my knowledge of how a Rpi boots is non existent though I do believe there are different run levels?
I'm assuming the script does not need a user logged in for it to run during the boot sequence!?
Re: Service wont Start on Boot
Posted: Wed Sep 09, 2015 1:26 am
by KLL
hp1975 wrote:I'm assuming the script does not need a user logged in for it to run during the boot sequence!?
yes, no login / auto login to desktop ... required
operation:
sudo /etc/init.d/radio start
sudo /etc/init.d/radio stop
sudo /etc/init.d/radio restart now you should see if there is a problem
Re: Service wont Start on Boot
Posted: Wed Sep 09, 2015 5:49 am
by hp1975
Restart works fine.
So i need to set up an autlogin for this to work?
Will this work for a RPi2?
http://www.opentechguides.com/how-to/ar ... start.html
Re: Service wont Start on Boot
Posted: Wed Sep 09, 2015 7:36 am
by RaTTuS
sudo /etc/init.d/radio restart
if that works then it will work on reboot ,
no auto login needed
if it does not work on reboot then there is something else wrong
maybe some other service is not yet started
Re: Service wont Start on Boot
Posted: Wed Sep 09, 2015 8:24 am
by hp1975
Mmmm OK, I don't suppose there is an 'easy' way of diagnosing whether there is another service that is (or is not) starting that may be prevented this one from starting?
Re: Service wont Start on Boot
Posted: Wed Sep 09, 2015 9:51 am
by hp1975
Sorry if this is a stupid question but does it matter that the Python script is located in the /home/pi/radio/ directory?
I mean, isn't that directory only accessible after login?
Re: Service wont Start on Boot
Posted: Wed Sep 09, 2015 9:53 am
by rpdom
hp1975 wrote:Sorry if this is a stupid question but does it matter that the Python script is located in the /home/pi/radio/ directory?
I mean, isn't that directory only accessible after login?
No. It doesn't matter. That directory is always accessible by any program with the right permissions.
Re: Service wont Start on Boot
Posted: Wed Sep 09, 2015 11:09 am
by RaTTuS
hp1975 wrote:Mmmm OK, I don't suppose there is an 'easy' way of diagnosing whether there is another service that is (or is not) starting that may be prevented this one from starting?
loog in the logs
check out dmesg
also check out /var/log/syslog
you may find something to help
Re: Service wont Start on Boot
Posted: Wed Sep 09, 2015 11:13 am
by hp1975
Thanks RaTTuS. Is there anything I should be looking for....error messages etc?
Is it worth trying to Auto start via rc.local or cron instead or am I likely to have the same issue?
Re: Service wont Start on Boot
Posted: Wed Sep 09, 2015 11:17 am
by RaTTuS
no idea
just look
leave it as an update.rc script and see if you can find out why
if having checked things and then doing a service restart yoou fail to find thing then post the logs and maybe someone can spot something
use
pastebin for longer info
sudo apt-get install pastebinit
cat /var/log/syslog | pastebinit
for example
Re: Service wont Start on Boot
Posted: Wed Sep 09, 2015 5:07 pm
by DougieLawson
Try
sudo update-rc.d radio enable
That creates the symbolic links in /etc/rc2.d, /etc/rc0.d and /etc/rc6.d to get radio started at boot and closed at reboot or halt.
Re: Service wont Start on Boot
Posted: Wed Sep 09, 2015 8:01 pm
by hp1975
I did update-rc enable and the symbolic links are all there (I assume the links are just copies of the script!).
Ive checked the logs, there is no mention of 'radio' (used grep)in any of the logs. Should I at least see something that says the service has started?
There were some errors, but googling they are common ones during boot and can be ignored.
Unfortunately still no joy, the radio script doesnt come to life on reboot bur does when I do sudo service......
Thanks for all the help folks, very frustrating!
Re: Service wont Start on Boot [solved, sort of]
Posted: Wed Sep 09, 2015 9:13 pm
by hp1975
I just added
sudo service radio start to /etc/rc.local and it works.
I'm frustrated that i couldnt get it to work via init.d but happy that the script now runs on boot.
Thanks for all the advice.
Re: Service wont Start on Boot [solved, sort of]
Posted: Thu Sep 10, 2015 8:03 am
by RaTTuS
hp1975 wrote:I just added
sudo service radio start to /etc/rc.local and it works.
I'm frustrated that i couldnt get it to work via init.d but happy that the script now runs on boot.
Thanks for all the advice.
when it starts what appears in the logs
cat /var/log/messages
or
cat /var/log/syslog
Re: Service wont Start on Boot
Posted: Thu Sep 10, 2015 7:56 pm
by hp1975
Maybe i'm looking for the wrong thing but i cant see a single reference to 'radio' or a service starting (that might be the radio one) in syslog, messages, syslog.1 or dmesg?