109 lines
2.7 KiB
Bash
109 lines
2.7 KiB
Bash
#!/bin/sh
|
|
|
|
### BEGIN INIT INFO
|
|
# Provides: mpd
|
|
# Required-Start: $local_fs $remote_fs +autofs +network +pulseaudio
|
|
# Required-Stop: $local_fs $remote_fs +autofs +network +pulseaudio
|
|
# Default-Start: 3 5
|
|
# Default-Stop: 0 6
|
|
# Short-Description: Music Player Daemon
|
|
# Description: Start the Music Player Daemon (MPD) service
|
|
# for network access to the local audio queue.
|
|
### END INIT INFO
|
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
NAME=mpd
|
|
DESC="Music Player Daemon"
|
|
DAEMON=/usr/bin/mpd
|
|
MPDCONF=/etc/mpd.conf
|
|
|
|
# Exit if the package is not installed
|
|
[ -x "$DAEMON" ] || exit 0
|
|
|
|
# Read configuration variable file if it is present
|
|
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
|
|
|
|
if [ -n "$MPD_DEBUG" ]; then
|
|
set -x
|
|
MPD_OPTS=--verbose
|
|
fi
|
|
|
|
PIDFILE=$(sed -n 's/^[[:space:]]*pid_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF)
|
|
|
|
mpd_start () {
|
|
boot_mesg "Starting $DESC: $NAME"
|
|
|
|
if [ -z "$PIDFILE" ]; then
|
|
log_failure_msg \
|
|
"$MPDCONF must have pid_file set; cannot start daemon."
|
|
exit 1
|
|
fi
|
|
|
|
PIDDIR=$(dirname "$PIDFILE")
|
|
if [ ! -d "$PIDDIR" ]; then
|
|
mkdir -m 0755 $PIDDIR
|
|
if dpkg-statoverride --list --quiet /run/mpd > /dev/null; then
|
|
# if dpkg-statoverride is used update it with permissions there
|
|
dpkg-statoverride --force --quiet --update --add $( dpkg-statoverride --list --quiet /run/mpd ) 2> /dev/null
|
|
else
|
|
# use defaults
|
|
chown mpd:audio $PIDDIR
|
|
fi
|
|
fi
|
|
|
|
start-stop-daemon --start --quiet --oknodo --pidfile "$PIDFILE" \
|
|
--exec "$DAEMON" -- $MPD_OPTS "$MPDCONF"
|
|
evaluate_retval
|
|
}
|
|
|
|
mpd_stop () {
|
|
if [ -z "$PIDFILE" ]; then
|
|
log_failure_msg \
|
|
"$MPDCONF must have pid_file set; cannot stop daemon."
|
|
exit 1
|
|
fi
|
|
|
|
boot_mesg "Stopping $DESC: $NAME"
|
|
start-stop-daemon --stop --quiet --oknodo --retry 5 --pidfile "$PIDFILE" \
|
|
--exec $DAEMON
|
|
evaluate_retval
|
|
}
|
|
|
|
mpd_status () {
|
|
if start-stop-daemon --status -p $PIDFILE $NAME > /dev/null; then
|
|
echo "$DESC ${NAME} is running"
|
|
exit 0
|
|
else
|
|
echo "$DESC ${NAME} is not running"
|
|
exit 3
|
|
fi
|
|
}
|
|
|
|
# note to self: don't call the non-standard args for this in
|
|
# {post,pre}{inst,rm} scripts since users are not forced to upgrade
|
|
# /etc/init.d/mpd when mpd is updated
|
|
case "$1" in
|
|
start)
|
|
mpd_start
|
|
;;
|
|
stop)
|
|
mpd_stop
|
|
;;
|
|
status)
|
|
mpd_status
|
|
;;
|
|
restart|force-reload|force-restart)
|
|
mpd_stop
|
|
mpd_start
|
|
;;
|
|
force-start)
|
|
mpd_start
|
|
;;
|
|
*)
|
|
echo "Usage: $0 {start|stop|status|restart|force-reload|force-restart|force-start}"
|
|
exit 2
|
|
;;
|
|
esac
|