Don't you think of ``daemontools'' as just trivial kits for rigid administrators?
daemontools can also be used to control user-level daemons. Here I describe how to implement easy remote control for mpg123 using daemontools. The function is simple, but suitable for those who want to simply play mp3 files, but don't want mouse operation or cumbersome windows.
``supervise'' tries to restart 1 second after the process it supervises terminated. So you can make use of this feature for repeating songs. Let the ``run'' script pass a playlist to mpg123, and you can control it by invoking svc, as follows:
Cool, isn't it?
It is, say,
$ mkdir /home/yusuke/.mp3play
run script goes as follows:
#!/bin/sh exec mpg123 `cat /home/yusuke/.mp3play/list`
Place this into your
.mp3play directory with
supervise performs mutual exclusion, so you don't worry about doubly launched supervises. Start it in any script as you like, but you don't need to use svscan here.
I put the following line into my
supervise /home/yusuke/.mp3play >/dev/null 2>&1 &
supervise tries to launch the
immediately after it starts. You will be surprised
your machine suddenly begins to play your favorites. (I had a case!)
To avoid this, place empty
down file into
your supervise directory in advance. It prevents supervise
from launching at first time. It's like
svc -d at
$ touch /home/yusuke/.mp3play/down
/home/yusuke/.mp3play/ should look like this:
$ ls -l /home/yusuke/.mp3play -rw-r--r-- 1 yusuke 0 Feb 10 15:47 down -rwxr-xr-x 1 yusuke 46 Feb 10 15:40 run
Finally, place a shell script for play control into your path:
#!/bin/sh SVCDIR=/home/yusuke/.mp3play # stop playing first. svc -d $SVCDIR # immediately return if no file is specified. if [ ! "$1" ]; then exit; fi # put the files into the playlist. find "$@" -name '*.mp3' > $SVCDIR/list # restart playing. svc -u $SVCDIR
This script adds all
*.mp3 files under specified directories
into the playlist and signal supervise to start playing.
If you don't like autorepeat, modify the last line
svc -u' into '
If this script is named like
you can play all mp3 files under
/mp3/sc/ by typing:
$ mp /mp3/sc
You might want to add the following aliases or shell-functions:
alias first='svc -t /home/yusuke/.mp3play' # play from the beginning of the list alias once='svc -o /home/yusuke/.mp3play' # play once alias rept='svc -u /home/yusuke/.mp3play' # play repeatedly alias stop='svc -d /home/yusuke/.mp3play' # stop playing alias next='svc -i /home/yusuke/.mp3play' # play the next one
What is neat in supervise is that you can alter repeating mode
svc -o (once) and
svc -u (repeat).
If you started playing by
svc -o and
changed your mind afterward, type
It will be tuned into repeat mode (vice versa).
Last modified: Sat May 18 16:35:55 2002Yusuke Shinyama