#!/bin/bash # # Init file for Music Player Daemon [ -x /usr/bin/mpd ] || exit 1 [ -r /etc/mpd.conf ] || exit 1 start() { mkdir -p /run/mpd chown mpd:mpd /run/mpd echo "Starting mpd: /usr/bin/mpd /etc/mpd.conf" su mpd -c "/usr/bin/mpd /etc/mpd.conf" } stop() { echo -n "Shutting down mpd: " [ ! -z "$(pidof /usr/bin/mpd)" ] && su mpd -c "/usr/bin/mpd --kill" echo } restart(){ stop sleep 1 start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) if [ -z "$(pidof /usr/bin/mpd)" ]; then echo "Status mpd: not running" else echo "Status mpd: running with pid $(pidof /usr/bin/mpd)" fi ;; *) echo "Usage: $0 {start|stop|restart|status}" esac