I've started using my second mpd again, so here are the changes I've
made to lastmp 0.37-2 to accommodate it.
The main change is adding the --config option to lastmp. The value passed
determines which section to consult in /etc/lastmp.conf, defaulting to mpd.
The config value is appended to the name passed to lastfm.client.Daemon
so that each lastmp instance gets a unique pid file. The init script is
adjusted to reflect this.
With these changes, adding a new instance consists of adding a new
section to /etc/lastmp.conf, copying /etc/init.d/lastmp and adjusting
$LASTMP_CONFIG and finally creating startup links and whatnot.
diff --git a/debian/lastmp.init.d b/debian/lastmp.init.d
index ac01562..61c995d 100644
--- a/debian/lastmp.init.d
+++ b/debian/lastmp.init.d
@@ -17,6 +17,11 @@ RUNDIR=/var/run/lastfm
USER=lastfm
GROUP=lastfm
+LASTMP_CONFIG=mpd
+DAEMON_OPTS=--config $LASTMP_CONFIG
+
+PIDFILE=$RUNDIR/${NAME}_${LASTMP_CONFIG}.pid
+
if ! [ -x $DAEMON ]; then
exit 0
fi
@@ -25,23 +30,23 @@ case $1 in
start)
echo -n Starting $DESC:
start-stop-daemon --quiet --start -c $USER:$GROUP \
---pidfile $RUNDIR/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
-echo $NAME.
+--pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
+echo $NAME ($LASTMP_CONFIG).
;;
stop)
echo -n Stopping $DESC:
start-stop-daemon --quiet --oknodo --stop -u $USER \
---pidfile $RUNDIR/$NAME.pid
-echo $NAME.
+--pidfile $PIDFILE
+echo $NAME ($LASTMP_CONFIG).
;;
restart|force-reload)
echo -n Restarting $DESC:
start-stop-daemon --quiet --oknodo --stop -u $USER \
---pidfile $RUNDIR/$NAME.pid
+--pidfile $PIDFILE
sleep 1
start-stop-daemon --quiet --start -c $USER:$GROUP \
---pidfile $RUNDIR/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
-echo $NAME.
+--pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS
+echo $NAME ($LASTMP_CONFIG).
;;
*)
N=/etc/init.d/$NAME
diff --git a/lastmp b/lastmp
index 7223fca..a714716 100755
--- a/lastmp
+++ b/lastmp
@@ -13,7 +13,7 @@ import lastfm.config
import lastfm.marshaller
DAEMON_NAME = 'lastmp'
-USAGE = 'usage: %s [--debug] [--no-daemon] [--help]' % DAEMON_NAME
+USAGE = 'usage: %s [--config CONFIG] [--debug] [--no-daemon] [--help]' %
DAEMON_NAME
# If the system load is high, we may not wake again until slightly
# longer than we slept. This should really be like 0.1, but
@@ -173,11 +173,11 @@ class MPDMonitor:
self.cli.log.error(Can't write sub: %s % e)
class LmpConfig(lastfm.config.Config):
-def __init__(self):
+def __init__(self, config):
lastfm.config.Config.__init__(self, search=DAEMON_NAME)
-self.host = self.cp.get('mpd', 'host', None)
-self.port = int(self.cp.get('mpd', 'port', 6600))
-self.password = self.cp.get('mpd', 'password', None)
+self.host = self.cp.get(config, 'host', None)
+self.port = int(self.cp.get(config, 'port', 6600))
+self.password = self.cp.get(config, 'password', None)
if not self.host:
raise NoHostError
@@ -196,8 +196,8 @@ def daemon(cli):
mo.observe()
if __name__ == '__main__':
-shortopts = 'dnh'
-longopts = ['debug', 'no-daemon', 'help']
+shortopts = 'c:dnh'
+longopts = ['config=', 'debug', 'no-daemon', 'help']
try:
opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
@@ -206,12 +206,15 @@ if __name__ == '__main__':
print sys.stderr, USAGE
sys.exit(1)
+config = 'mpd'
debug = False
fork = True
stderr = False
for opt, arg in opts:
-if opt in ('--debug', '-d'):
+if opt in ('--config', '-c'):
+config = arg
+elif opt in ('--debug', '-d'):
debug = True
elif opt in ('--no-daemon', '-n'):
fork = False
@@ -221,14 +224,14 @@ if __name__ == '__main__':
sys.exit(0)
try:
-conf = LmpConfig()
+conf = LmpConfig(config)
except NoHostError:
print sys.stderr, '%s: no MPD host specified' % DAEMON_NAME
sys.exit(1)
if conf.debug:
debug = True
-cli = lastfm.client.Daemon(DAEMON_NAME, conf)
+cli = lastfm.client.Daemon(DAEMON_NAME + _ + config, conf)
cli.daemonize(fork)
cli.open_log(debug, stderr)
--
Paul Collins
Wellington, New Zealand
Dag vijandelijk luchtschip de huismeester is dood
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]