CentOS6.x MPD 自動起動設定

<<トップページへ

■概要

CentOS6.x でMPDを自動に起動するための設定をします。Debian、ubuntuでは必要ありません。

mpd自動起動設定

/etc/init.d/mpdを作成する。

 /etc/rc.localからの起動で問題ないがubuntu12.04の真似をした(笑)ただし、本末転倒であるが
起動スクリプトの中で使われているdpkg-statoverrideはrpm系であるCentOSには存在しない。
そこでdpkg-1.15.5.6-6.el6.x86_64をepel.repoからインストールした。

$ cat /etc/init.d/mpd
#!/bin/sh

### BEGIN INIT INFO
# Provides:          mpd
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 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

. /lib/lsb/init-functions

PATH=/usr/local/bin:/bin:/usr/bin
NAME=mpd
DESC="Music Player Daemon"
DAEMON=/usr/local/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

if [ ! -d "/var/run/mpd" ]; then
mkdir /var/run/mpd
if dpkg-statoverride --list --quiet /var/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 /var/run/mpd ) 2> /dev/null
        else
                #use defaults
                chown mpd:audio /var/run/mpd
                chmod 755 /var/run/mpd
        fi
fi

DBFILE=$(sed -n 's/^[[:space:]]*db_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF)
PIDFILE=$(sed -n 's/^[[:space:]]*pid_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p' $MPDCONF)
USER=`awk 'BEGIN{ao=0} /[ \t]*audio_output[ \t]*{/{ ao = 1 } /[ \t]*}/{ ao = 0 } /^[ \t]*user[ \t]*/{ if (ao == 0) user = $2 } END{ print substr(user, 2, length(user) - 2) }' $MPDCONF`

mpd_start () {

 # Start daemons.

 ls /var/run/mpd/mpd.pid > /dev/null 2>&1
 if [ $? -ne 0 ]; then
 echo -n "Startup mpd"
 for pid in /var/run/mpd/mpd.pid
 do
 /usr/local/bin/mpd /etc/mpd.conf
 done
 echo
 else
 echo "mpd is running"
 fi

}

mpd_stop () {
 # Stop daemons.
 ls /var/run/mpd/mpd.pid > /dev/null 2>&1
 if [ $? -eq 0 ]; then
 echo -n "Shutting down mpd"
 for pid in /var/run/mpd/mpd.pid
 do
 kill $(cat $pid)
 rm -f $pid
 done
 echo
#rm -f /var/lock/subsys/swatch /tmp/.swatch_script.*
 else
 echo "mpd is not running"
 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)
        status_of_proc -p $PIDFILE $DAEMON $NAME
        ;;
    restart|force-reload)
        mpd_stop
        mpd_start
        ;;
    force-start)
        mpd_start
        ;;
    force-restart)
        mpd_stop
        mpd_start
        ;;
    force-reload)
        mpd_stop
        mpd_start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|force-reload}"
        exit 2
        ;;
esac

ここまでやると
# /etc/init.etc mpd start  でmpdを起動できる。

# chkconfig on mpd  でPC起動時に自動起動する。


参考HP
http://inaz2.hatenablog.com/entry/2013/07/10/180408
http://devlog.grim3lt.org/2013/06/usbdac-invictadsdnetbookaod250.html