[Pianod] Raspbian init script, sbin versus bin

Peter Li chinasaurli at gmail.com
Sun Feb 24 19:38:23 PST 2013


Okay, I took a stab at writing an init.d script for Raspbian.  It's a 
little ugly, but hopefully it will allow more RasPi users to try 
pianod.  Looking at my Fedora system, it doesn't appear that this will 
work there, so I've named it pianod.raspbian.init.  On a Raspbian 
system, it should be moved/renamed to /etc/init.d/pianod to get the 
daemon running on boot.

If there's anyone else on the list running Raspbian, would be great to 
get a test.

Note that I changed the default pianod location to /usr/sbin/pianod.  
contrib/pianod.service should probably be updated to use this default 
location as well.
-------------- next part --------------
#! /bin/sh
### BEGIN INIT INFO
# Provides:          pianod
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts pianod
# Description:       pianod is a clent/server for Pandora.  This init script
#                    copied and repurposed from RasPi init.d/lirc and init.d/ntp
### END INIT INFO

# TODO
# Should add a pianod.conf file option to define port, initscript, and
# userfile locations

DAEMON=/usr/sbin/pianod

. /lib/lsb/init-functions
test -f $DAEMON || exit 0

case "$1" in
  start)
    log_daemon_msg "Starting pianod"

    if [ ! -f /etc/pianod.startscript ]; then
      log_warning_msg "/etc/pianod.startscript not found"
      log_end_msg 1
    else
      start-stop-daemon --start --background --quiet --exec $DAEMON -- -i /etc/pianod.startscript
      exitval=$?

      if [ $exitval = 0 ]; then
        start-stop-daemon --status --exec $DAEMON
        exitval=$?
        
        # Wait a little while...
        if [ $exitval = 3 ]; then
          sleep 0.5
          start-stop-daemon --status --exec $DAEMON
          exitval=$?
        fi

        # Wait a little more...
        if [ $exitval = 3 ]; then
          sleep 0.5
          start-stop-daemon --status --exec $DAEMON
          exitval=$?
        fi

        # Wait a little more...
        if [ $exitval = 3 ]; then
          sleep 0.5
          start-stop-daemon --status --exec $DAEMON
          exitval=$?
        fi

        log_end_msg $exitval
      else
        log_end_msg $exitval
      fi
    fi
    ;;

  stop)
    log_daemon_msg "Stopping pianod"
    start-stop-daemon --stop --quiet --exec $DAEMON
    log_end_msg $?
    ;;

  restart|reload|force-reload)
    $0 stop
    sleep 1
    $0 start
    ;;

  status)
    status_of_proc $DAEMON "pianod"
    ;;

  *)
    echo "Usage: /etc/init.d/lircd {start|stop|status|reload|restart|force-reload}"
    exit 1
    ;;
esac

exit 0


More information about the Pianod mailing list