Add support for pausing MPlayer
[headphoned] / debian / headphoned.zheadphoned.init
1 #! /bin/sh
2 #
3 # skeleton      example file to build /etc/init.d/ scripts.
4 #               This file should be used to construct scripts for /etc/init.d.
5 #
6 #               Written by Miquel van Smoorenburg <miquels@cistron.nl>.
7 #               Modified for Debian 
8 #               by Ian Murdock <imurdock@gnu.ai.mit.edu>.
9 #
10 # Version:      @(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
11 #
12
13 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
14 DAEMON=/usr/sbin/headphoned
15 NAME=headphoned
16 USER=user
17 DESC="Headphone daemon"
18
19 # XXX: The following is needed for the D-Bus connection to work
20 export DBUS_SESSION_BUS_ADDRESS='unix:path=/tmp/session_bus_socket'
21 # XXX end
22
23 # Add the headphoned FIFO to MPlayer's global configuration
24 CONFIG_LINE="input:file=/etc/headphoned/mplayer-input"
25 MPLAYER_CONF="/etc/mplayer/mplayer.conf"
26 if [ -f "$MPLAYER_CONF" ]; then
27         if ! grep "$CONFIG_LINE" "$MPLAYER_CONF" >/dev/null; then
28                 echo -n "Updating $MPLAYER_CONF... "
29                 echo $CONFIG_LINE >>$MPLAYER_CONF
30                 echo "done."
31         fi
32 fi
33 # End Add the headphoned FIFO to MPlayer's global configuration
34
35 test -x $DAEMON || exit 0
36
37 set -e
38
39 case "$1" in
40   start)
41         echo -n "Starting $DESC: "
42         start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
43                 -b --user $USER --chuid $USER --exec $DAEMON -- $DAEMON_OPTS
44         echo "$NAME."
45         ;;
46   stop)
47         echo -n "Stopping $DESC: "
48         _PIDS=`pidof $DAEMON || echo ""`
49         if [ "$_PIDS" != "" ]; then
50                 kill $_PIDS
51         fi
52         #start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
53         #       --user $USER --chuid $USER --exec $DAEMON
54         echo "$NAME."
55         ;;
56   reload)
57         #
58         #       If the daemon can reload its config files on the fly
59         #       for example by sending it SIGHUP, do it here.
60         #
61         #       If the daemon responds to changes in its config file
62         #       directly anyway, make this a do-nothing entry.
63         #
64         # echo "Reloading $DESC configuration files."
65         # start-stop-daemon --stop --signal 1 --quiet --pidfile \
66         #       /var/run/$NAME.pid --exec $DAEMON
67         ;;
68   force-reload)
69         #
70         #       If the "reload" option is implemented, move the "force-reload"
71         #       option to the "reload" entry above. If not, "force-reload" is
72         #       just the same as "restart" except that it does nothing if the
73         #   daemon isn't already running.
74         # check wether $DAEMON is running. If so, restart
75         #start-stop-daemon --stop --test --quiet --pidfile \
76         #       --user $USER --chuid $USER /var/run/$NAME.pid --exec $DAEMON \
77         #&& $0 restart \
78         #|| exit 0
79         ;;
80   restart)
81     echo -n "Restarting $DESC: "
82         _PIDS=`pidof $DAEMON || echo ""`
83         if [ "$_PIDS" != "" ]; then
84                 kill $_PIDS
85         fi
86         #start-stop-daemon --stop --quiet --pidfile \
87         #       --user $USER --chuid $USER /var/run/$NAME.pid --exec $DAEMON
88         sleep 1
89         start-stop-daemon --start --quiet --pidfile -b --user $USER \
90                 --chuid $USER /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
91         echo "$NAME."
92         ;;
93   *)
94         N=/etc/init.d/$NAME
95         # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
96         echo "Usage: $N {start|stop|restart|force-reload}" >&2
97         exit 1
98         ;;
99 esac
100
101 exit 0