#!/bin/sh # # $Id$ # # logitechmediaserver initscript for slimserver.pl # This file should be placed in /etc/init.d. # # Original Author: Mattias Holmlund # # Updated By: Dan Sully, Michael Herger # ### BEGIN INIT INFO # Provides: logitechmediaserver # Required-Start: $all # Required-Stop: $all # Should-Start: $all # Should-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Startup script for the Logitech Media Server # Description: Logitech Media Server powers the Squeezebox, Transporter and SLIMP3 network music \ # players and is the best software to stream your music to any software MP3 \ # player. It supports MP3, AAC, WMA, FLAC, Ogg Vorbis, WAV and more! \ # As of version 7.7 it also supports UPnP clients, serving pictures and movies too!" ### END INIT INFO # # Using the lsb functions to perform the operations. . /lib/lsb/init-functions PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="Logitech Media Server" NAME=squeezeboxserver NEWNAME=logitechmediaserver DAEMON=/usr/sbin/$NAME DAEMON_SAFE=/usr/sbin/${NAME}_safe PIDFILE=/var/run/$NEWNAME.pid SCRIPTNAME=/etc/init.d/$NEWNAME SLIMUSER=$NAME SLIMGROUP=$(id -ng $SLIMUSER) PREFSDIR=/var/lib/$NAME/prefs LOGDIR=/var/log/$NAME/ CACHEDIR=/var/lib/$NAME/cache CHARSET=utf8 SLIMOPTIONS= # Read config file if it is present. if [ -r /etc/default/$NEWNAME ]; then . /etc/default/$NEWNAME elif [ -r /etc/default/$NAME ]; then . /etc/default/$NAME fi d_check_running() { if [ -e $PIDFILE ]; then pidofproc -p "$PIDFILE" "$DAEMON" > /dev/null 2>&1 && status=0 || status=$? if [ $status -eq 0 ]; then log_daemon_msg "${DESC} is already running" log_end_msg 0 exit 0 fi fi } d_start() { d_check_running log_daemon_msg "Starting" "$DESC" # Use squeezeboxserver_safe to restart the daemon when # it dies. This must be done to handle mysql restarts. if start-stop-daemon --start --quiet \ --chuid $SLIMUSER \ --pidfile $PIDFILE \ --exec $DAEMON_SAFE \ --background \ --make-pidfile \ -- \ $DAEMON \ --prefsdir $PREFSDIR \ --logdir $LOGDIR \ --cachedir $CACHEDIR \ --charset=$CHARSET \ $SLIMOPTIONS ; then log_end_msg 0 else log_end_msg 1 fi } d_start_direct() { d_check_running log_daemon_msg "Starting" "$DESC" # Make the pid file writeable by lms touch $PIDFILE chown "${SLIMUSER}:${SLIMGROUP}" $PIDFILE if start-stop-daemon --start --quiet \ --chuid $SLIMUSER \ --pidfile $PIDFILE \ --exec $DAEMON \ --background \ --make-pidfile \ -- \ --pidfile $PIDFILE \ --prefsdir $PREFSDIR \ --logdir $LOGDIR \ --cachedir $CACHEDIR \ --charset=$CHARSET \ $SLIMOPTIONS ; then log_end_msg 0 else log_end_msg 1 fi } # Function that stops the daemon/service. # d_stop() { if [ -e $PIDFILE ]; then status_of_proc -p "$PIDFILE" "$DAEMON" "$DESC" > /dev/null 2>&1 && status=0 || status=$? if [ $status -eq 0 ]; then log_daemon_msg "Stopping" "$DESC" if start-stop-daemon --oknodo --stop --quiet --pidfile "$PIDFILE" --retry=TERM/30/KILL/5 ; then /bin/rm -rf $PIDFILE log_end_msg 0 else log_end_msg 1 fi fi else # status 3: program is not running status=3 fi if [ $status -gt 0 ]; then # status 1: program is dead and /var/run pid file exists log_daemon_msg "${NEWNAME} is not running" #exit $status fi return $status } d_status() { if [ -e $PIDFILE ]; then status_of_proc -p "$PIDFILE" "$DAEMON" "$DESC" && exit 0 || exit $? else log_daemon_msg "${DESC} is not running" log_end_msg 3 fi } # # Function that sends a SIGHUP to the daemon/service. # d_reload() { start-stop-daemon --stop --quiet --pidfile $PIDFILE --signal 1 } case "$1" in start) d_start ;; start-direct) d_start_direct ;; stop) d_stop ;; restart|force-reload) d_stop d_start ;; status) d_status ;; *) echo "Usage: $SCRIPTNAME {start|start-direct|stop|restart|force-reload|status}" >&2 exit 2 ;; esac exit 0