1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/bin/sh -e
if [ -n "$MPD_DEBUG" ]; then
set -x
MPD_OPTS=--verbose
fi
umask 0022
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# edit /etc/default/mpd to change these:
DAEMON=/usr/bin/mpd
MPDCONF=/etc/mpd.conf
START_MPD=true
if [ -r /etc/default/mpd ]; then
. /etc/default/mpd
fi
check_conf () {
if ! (grep -q db_file $MPDCONF && grep -q pid_file $MPDCONF); then
echo "$MPDCONF must have db_file and pid_file set; not starting."
exit 0
fi
}
check_dbfile () {
DBFILE=`sed -n -e 's/^[[:space:]]*db_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF`
if [ "$FORCE_CREATE_DB" -o ! -f "$DBFILE" ]; then
echo -n "creating $DBFILE... "
$DAEMON --create-db "$MPDCONF" > /dev/null 2>&1
fi
}
mpd_start () {
if [ "$START_MPD" != "true" ]; then
echo "Not starting MPD: disabled by /etc/default/mpd."
exit 0
fi
echo -n "Starting Music Player Daemon: "
check_conf
check_dbfile
if $DAEMON $MPD_OPTS "$MPDCONF"; then
echo "mpd."
else
echo "failed."
fi
}
mpd_stop () {
echo -n "Stopping Music Player Daemon: "
if $DAEMON --kill "$MPDCONF" >/dev/null 2>&1; then
echo "mpd."
else
echo "not running or no pid_file set."
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
;;
restart|reload)
mpd_stop
mpd_start
;;
force-start|start-create-db)
FORCE_CREATE_DB=1
mpd_start
;;
force-restart|force-reload)
FORCE_CREATE_DB=1
mpd_stop
mpd_start
;;
*)
echo "Usage: $0 {start|start-create-db|stop|restart|reload}"
exit 1
;;
esac
|