Hello,
I also want to run multiple instances of mpd. I patched mpd-0.15.15 to
start an instance for each config-file which is found in
/etc/mpd/instances if there is no /etc/mpd.conf. The patch is attached.
What I don't like about it yet is, that the user has to take care that
each config file has a different pid_file and statefile. Especially the
pid_file is tricky. If you change it, the instance will not be stopped
anymore.
I think it would be better to let the user only specify port and
audio_device for each instance so that he doesn't have to worry about
the pid_files and state_files. If we want to do this, we have to patch
the main program and pass these two parameters as arguments instead of
the config file. The pid-files would all be placed in /var/pid/mpd and
/etc/init.d/stop would stop the instances for all pid-files regardless
of what is written in the configs. What do you think about it?
Christian
diff -Naur ../mpd-original/mpd-0.15.15/debian/README.Debian
mpd-0.15.15/debian/README.Debian
--- ../mpd-original/mpd-0.15.15/debian/README.Debian 2011-01-06
12:03:08.000000000 +0100
+++ mpd-0.15.15/debian/README.Debian 2011-01-06 12:53:43.000000000 +0100
@@ -15,6 +15,12 @@
value to an appropriate interface, or comment it out to enable listening
on all network interfaces.
+If you want to start multiple instances of mpd as a system service, place
+a .conf file for each instance in /etc/mpd/instances and delete /etc/mpd.conf.
+Be carefull that you do add or remove new instance only when mpd is stopped.
+Make sure that each instance has a different pid_file, state_file and port.
+Probably you want to specify a different audio_output for each, too.
+
When using ALSA with dmix, you may run into problems sharing the sound card
between the "mpd" user and your own account. A workaround is to use ALSA's
"ipc_key_add_uid" and "ipc_perm" directives. See the ALSA documentation for
diff -Naur ../mpd-original/mpd-0.15.15/debian/mpd.dirs
mpd-0.15.15/debian/mpd.dirs
--- ../mpd-original/mpd-0.15.15/debian/mpd.dirs 2011-01-06 12:03:08.000000000
+0100
+++ mpd-0.15.15/debian/mpd.dirs 2011-01-06 11:24:13.000000000 +0100
@@ -1,4 +1,6 @@
etc
+etc/mpd
+etc/mpd/instances
usr/bin
usr/share/man/man1
var/log/mpd
diff -Naur ../mpd-original/mpd-0.15.15/debian/mpd.init.d
mpd-0.15.15/debian/mpd.init.d
--- ../mpd-original/mpd-0.15.15/debian/mpd.init.d 2011-01-06
12:03:08.000000000 +0100
+++ mpd-0.15.15/debian/mpd.init.d 2011-01-06 13:08:36.000000000 +0100
@@ -16,29 +16,83 @@
. /lib/lsb/init-functions
PATH=/sbin:/bin:/usr/sbin:/usr/bin
+PKGNAME=mpd
NAME=mpd
+CONFIG_DIR=/etc/mpd/instances
DESC="Music Player Daemon"
DAEMON=/usr/bin/mpd
-MPDCONF=/etc/mpd.conf
+MPDCONF_SINGLE_INSTANCE=/etc/mpd.conf
START_MPD=true
# 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
+[ -r /etc/default/$PKGNAME ] && . /etc/default/$PKGNAME
if [ -n "$MPD_DEBUG" ]; then
set -x
MPD_OPTS=--verbose
fi
-DBFILE=$(sed -n 's/^[[:space:]]*db_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p'
$MPDCONF)
-PIDFILE=$(sed -n 's/^[[:space:]]*pid_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p'
$MPDCONF)
+read_dbfilename () {
+ DBFILE=$(sed -n 's/^[[:space:]]*db_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p'
$MPDCONF)
+}
+read_pidfilename () {
+ PIDFILE=$(sed -n 's/^[[:space:]]*pid_file[[:space:]]*"\?\([^"]*\)\"\?/\1/p'
$MPDCONF)
+}
mpd_start () {
+ # If /etc/mpd.conf exists we start this single instance and
+ # nothing else. This way we are backward compatible
+ if [ -e $MPDCONF_SINGLE_INSTANCE ]; then
+ MPDCONF=$MPDCONF_SINGLE_INSTANCE
+ NAME=$PKGNAME
+ read_pidfilename
+ mpd_start_instance
+ else
+ # Start instances for each config file in $CONFIG_DIR
+ for CONFIG in `cd $CONFIG_DIR; ls *.conf 2> /dev/null`; do
+ NAME=${CONFIG%%.conf}
+ MPDCONF=$CONFIG_DIR/$CONFIG
+ read_pidfilename
+ mpd_start_instance
+ done
+ fi
+}
+
+mpd_stop () {
+ if [ -e $MPDCONF_SINGLE_INSTANCE ]; then
+ MPDCONF=$MPDCONF_SINGLE_INSTANCE
+ NAME=$PKGNAME
+ read_pidfilename
+ mpd_stop_instance
+ else
+ # We proceed the same way like in mpd_start
+ # The drawback of this strategy is that if configs are deleted in
+ # between, those instance will not be stopped. The same problem
+ # arises if the pid-file is changed in the config.
+ #
+ # The package openvpn solves this problem by not letting the pid file be
+ # configured in each config. Instead the pid-filename is calculated by
the
+ # name of the config file. All the pid files are there in one directory
+ # and for each existing pid file the instance is stopped no matter if
there
+ # is a config for that instance or not.
+ # To apply this solution to mpd, the pid filename would hava to be
passed as
+ # an argument
+ for CONFIG in `cd $CONFIG_DIR; ls *.conf 2> /dev/null`; do
+ NAME=${CONFIG%%.conf}
+ MPDCONF=$CONFIG_DIR/$CONFIG
+ read_pidfilename
+ mpd_stop_instance
+ done
+ fi
+}
+
+mpd_start_instance () {
+ read_dbfilename
if [ "$START_MPD" != "true" ]; then
- log_action_msg "Not starting MPD: disabled by /etc/default/$NAME".
+ log_action_msg "Not starting MPD: disabled by /etc/default/$PKGNAME".
exit 0
fi
@@ -66,9 +120,9 @@
log_end_msg $?
}
-mpd_stop () {
+mpd_stop_instance () {
if [ "$START_MPD" != "true" ]; then
- log_failure_msg "Not stopping MPD: disabled by /etc/default/$NAME".
+ log_failure_msg "Not stopping MPD: disabled by /etc/default/$PKGNAME".
exit 0
fi
if [ -z "$PIDFILE" ]; then