hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Service wont Start on Boot

Mon Sep 07, 2015 5:57 am

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:

Code: Select all

sudo service radio start
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.

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Service wont Start on Boot

Mon Sep 07, 2015 6:49 am

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'

hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Re: Service wont Start on Boot

Mon Sep 07, 2015 8:05 am

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

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Service wont Start on Boot

Mon Sep 07, 2015 8:35 am

the service should be in /etc/init.d
and links in the other folders
see
update-rc.d
[ man update-rc.d ]
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Re: Service wont Start on Boot

Mon Sep 07, 2015 11:49 am

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?

hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Re: Service wont Start on Boot

Mon Sep 07, 2015 8:39 pm

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

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Service wont Start on Boot

Tue Sep 08, 2015 3:51 am

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

hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Re: Service wont Start on Boot

Tue Sep 08, 2015 5:37 pm

@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!?

User avatar
KLL
Posts: 1453
Joined: Wed Jan 09, 2013 3:05 pm
Location: thailand
Contact: Website

Re: Service wont Start on Boot

Wed Sep 09, 2015 1:26 am

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

hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Re: Service wont Start on Boot

Wed Sep 09, 2015 5:49 am

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

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Service wont Start on Boot

Wed Sep 09, 2015 7:36 am

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
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Re: Service wont Start on Boot

Wed Sep 09, 2015 8:24 am

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?

hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Re: Service wont Start on Boot

Wed Sep 09, 2015 9:51 am

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?

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Service wont Start on Boot

Wed Sep 09, 2015 9:53 am

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.

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Service wont Start on Boot

Wed Sep 09, 2015 11:09 am

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
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Re: Service wont Start on Boot

Wed Sep 09, 2015 11:13 am

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?

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Service wont Start on Boot

Wed Sep 09, 2015 11:17 am

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
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Service wont Start on Boot

Wed Sep 09, 2015 5:07 pm

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.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Re: Service wont Start on Boot

Wed Sep 09, 2015 8:01 pm

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!

hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Re: Service wont Start on Boot [solved, sort of]

Wed Sep 09, 2015 9:13 pm

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. :D

Thanks for all the advice.

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Service wont Start on Boot [solved, sort of]

Thu Sep 10, 2015 8:03 am

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. :D

Thanks for all the advice.
when it starts what appears in the logs
cat /var/log/messages
or
cat /var/log/syslog
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

hp1975
Posts: 26
Joined: Sat Aug 22, 2015 5:09 pm

Re: Service wont Start on Boot

Thu Sep 10, 2015 7:56 pm

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?

Return to “Troubleshooting”