fix pidfile
[osspd.git] / debian / osspd.init
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          osspd
4 # Required-Start:    $remote_fs $syslog
5 # Required-Stop:     $remote_fs $syslog
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: OSS Proxy Daemon: Userland OSS emulation
9 # Description:       Daemon providing a userland implementation of OSS devices.
10 #                    Currently it supports forwarding OSS sound streams to
11 #                    PulseAudio and ALSA.
12 ### END INIT INFO
13
14 # Author: Ralf Jung <post@ralfj.de>
15
16 PATH=/sbin:/usr/sbin:/bin:/usr/bin
17 DESC=" OSS Proxy Daemon"
18 NAME=osspd
19 DAEMON=/usr/sbin/$NAME
20 DAEMON_ARGS="-f" # run in foreground, start-stop-daemon does the forking: required to let start-stop-daemon handle the pidfile
21 PIDFILE=/var/run/$NAME.pid
22 SCRIPTNAME=/etc/init.d/$NAME
23
24 # Exit if the package is not installed
25 [ -x "$DAEMON" ] || exit 0
26
27 # Define LSB log_* functions.
28 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
29 # and status_of_proc is working.
30 . /lib/lsb/init-functions
31
32 #
33 # Function that starts the daemon/service
34 #
35 do_start()
36 {
37         modprobe cuse # make sure the cuse module is loaded
38         # Return
39         #   0 if daemon has been started
40         #   1 if daemon was already running
41         #   2 if daemon could not be started
42         start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile --exec $DAEMON --test > /dev/null \
43                 || return 1
44         start-stop-daemon --start --background --quiet --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- -f \
45                 $DAEMON_ARGS \
46                 || return 2
47 }
48
49 #
50 # Function that stops the daemon/service
51 #
52 do_stop()
53 {
54         # Return
55         #   0 if daemon has been stopped
56         #   1 if daemon was already stopped
57         #   2 if daemon could not be stopped
58         #   other if a failure occurred
59         start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
60         return "$?"
61 }
62
63 case "$1" in
64   start)
65         log_daemon_msg "Starting $DESC" "$NAME"
66         do_start
67         case "$?" in
68                 0|1) log_end_msg 0 ;;
69                 2) log_end_msg 1 ;;
70         esac
71         ;;
72   stop)
73         log_daemon_msg "Stopping $DESC" "$NAME"
74         do_stop
75         case "$?" in
76                 0|1) log_end_msg 0 ;;
77                 2) log_end_msg 1 ;;
78         esac
79         ;;
80   status)
81         status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
82         ;;
83   restart|force-reload)
84         log_daemon_msg "Restarting $DESC" "$NAME"
85         do_stop
86         case "$?" in
87           0|1)
88                 do_start
89                 case "$?" in
90                         0) log_end_msg 0 ;;
91                         1) log_end_msg 1 ;; # Old process is still running
92                         *) log_end_msg 1 ;; # Failed to start
93                 esac
94                 ;;
95           *)
96                 # Failed to stop
97                 log_end_msg 1
98                 ;;
99         esac
100         ;;
101   *)
102         echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
103         exit 3
104         ;;
105 esac
106
107 :