# MPD - Music Player Daemon author "Bart Kroon " description "Music Player Daemon (MPD) service." version "0.1" start on (filesystem and static-network-up) stop on runlevel [!2345] env NAME=mpd env MPDCONF=/etc/mpd.conf export NAME export MPDCONF expect fork respawn respawn limit 10 5 pre-start script START_MPD=true # Read configuration variable file if it is present. [ -r /etc/default/$NAME ] && . /etc/default/$NAME if [ "$START_MPD" != "true" ]; then logger -t upstart "Not starting MPD: disabled by /etc/default/$NAME." stop ; exit 0 fi # Look trough the MPD config to find the pid_file and username MPD wants to use. PIDFILE=$(sed -n 's/^[[:space:]]*pid_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF) USER=`awk 'BEGIN{ao=0} /^[ \t]*user[ \t]*/{ if (ao == 0) user = $2 } END{ print substr(user, 2, length(user) - 2) }' $MPDCONF` if [ -n "$PIDFILE" ]; then # Create the directory where mpd will store the pid file and make sure # ownership and permissions are good to go. Otherwise MPD fails to start. PIDDIR=$(dirname "$PIDFILE") if [ ! -d $PIDDIR ]; then mkdir $PIDDIR if dpkg-statoverride --list --quiet $PIDDIR > /dev/null; then # If dpkg-statoverride is used update it with permissions there. dpkg-statoverride --force --quiet --update --add $( dpkg-statoverride --list --quiet $PIDDIR ) 2> /dev/null else # Otherwise use the values from MPD configuration. chown $USER:audio $PIDDIR chmod 755 $PIDDIR fi fi fi end script script # Read configuration variable file if it is present. [ -r /etc/default/$NAME ] && . /etc/default/$NAME exec mpd $MPDCONF end script