Script for init.d to start/stop the demon

646 views
Skip to first unread message

Brian Orpin

unread,
Dec 12, 2013, 8:28:53 AM12/12/13
to py...@googlegroups.com
So, first attempt at this so if there any glaring errors please let me know :)  This is to start the daemon at boot.  It does not check whether the daemon continues to run, or if it is logging.

This is a script to be placed in the /etc/init.d/ folder.  Edit any of the variables to suit your system.  Make it executable. 

Test it using /etc/init.d/pywws-livelog-daemon start 
check the status /etc/init.d/pywws-livelog-daemon status 
stop it with /etc/init.d/pywws-livelog-daemon stop 

It seems update-rc.d is being depreciated so I used insserv to set up the auto start links.

Firstly run it with the -n option which does not change anything.  If it is OK then run it again without the -n
sudo insserv -n -v pywws-livelog-daemon

Reboot the pi and chcck the status.

Start code;

#!/bin/sh

### BEGIN INIT INFO
# Provides:        pywws-livelog-daemon
# Required-Start:  $all
# Required-Stop:   $all
# Default-Start:   2 3 4 5
# Default-Stop:    0 1 6
# Short-Description: Start pywws daemon
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

. /lib/lsb/init-functions

DAEMON=/usr/local/bin/pywws-livelog-daemon.py
PIDFILE=/var/run/pywws.pid
DATADIR=/home/pi/weather/data
LOGFILE=$DATADIR/live_logger.log

RUNASUSER=pi
UGID=$(getent passwd $RUNASUSER | cut -f 3,4 -d:) || true

case $1 in
start)
log_daemon_msg "Starting pywws service" "pywws"
if [ -z "$UGID" ]; then
log_failure_msg "user \"$RUNASUSER\" does not exist"
exit 1
fi
$DAEMON -v $DATADIR $LOGFILE start 
status=$?
log_end_msg $status
  ;;
stop)
log_daemon_msg "Stopping pywws service" "pywws"
$DAEMON -v $DATADIR $LOGFILE stop
log_end_msg $?
rm -f $PIDFILE
  ;;
restart|force-reload)
$DAEMON -v $DATADIR $LOGFILE restart
  ;;
try-restart)
if $0 status >/dev/null; then
$0 restart
else
exit 0
fi
;;
reload)
exit 3
;;
status)
status_of_proc $DAEMON "pywws service"
;;
*)
echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
exit 2
;;
esac

Lee H-W

unread,
Jul 30, 2014, 6:06:28 AM7/30/14
to py...@googlegroups.com
had to change 
DAEMON=/usr/local/bin/pywws-livelog-daemon.py 
to
DAEMON=/usr/local/bin/pywws-livelog-daemon

for my build, then worked a treat

Neil Turner

unread,
Feb 6, 2015, 6:48:12 AM2/6/15
to py...@googlegroups.com
This worked very well thanks. I had to make the change suggested by Lee H-W removing the .py.   I also had to make the script executable ( sudo chmod a+x /etc/init.d/pywws-livelog-daemon). Neil

Ashley Jones

unread,
Mar 3, 2015, 7:16:55 AM3/3/15
to py...@googlegroups.com
This si working well for me too. Many thanks for posting Brian.

Steve Bird

unread,
Mar 3, 2015, 12:37:43 PM3/3/15
to py...@googlegroups.com
works well for me with .py removed.

Many thanks

Brian Orpin

unread,
May 1, 2015, 5:04:02 PM5/1/15
to py...@googlegroups.com
My guess is that the more recent builds create the file without the '.py' but I could be wrong!
Reply all
Reply to author
Forward
0 new messages