#!/bin/bash # # Init file for Snapcast server and client [ -x /usr/bin/snapserver ] || exit 1 [ -r /etc/default/snapcast ] || exit 1 RETVAL=0 # Read configuration . /etc/default/snapcast start() { if [ "$START_SNAPSERVER" == "true" ] ; then echo -n "Starting /usr/bin/snapserver $SNAPSERVER_OPTS" # Create pid directory on tmpfs mkdir -p /run/snapserver chown snapserver:snapserver /run/snapserver /usr/bin/snapserver $SNAPSERVER_OPTS sleep 0.5 echo fi if [ "$START_SNAPCLIENT" == "true" ] ; then echo -n "Starting /usr/bin/snapclient $SNAPCLIENT_OPTS" /usr/bin/snapclient $SNAPCLIENT_OPTS echo fi } stop() { if [ ! -z "$(pidof /usr/bin/snapclient)" ] ; then echo -n "Stopping snapclient: " kill $(pidof /usr/bin/snapclient) sleep 0.5 echo fi if [ ! -z "$(pidof /usr/bin/snapserver)" ] ; then echo -n "Stopping snapserver: " kill $(pidof /usr/bin/snapserver) sleep 0.5 echo fi } restart(){ stop start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) if [ -z "$(pidof /usr/bin/snapserver)" ]; then echo "Status snapserver: not running" else echo "Status snapserver: running with pid $(pidof /usr/bin/snapserver)" fi if [ -z "$(pidof /usr/bin/snapclient)" ]; then echo "Status snapclient: not running" else echo "Status snapclient: running with pid $(pidof /usr/bin/snapclient)" fi ;; *) echo "Usage: $0 {start|stop|restart|status}" esac