Switch to using std-init in invirt-console-server
[invirt/packages/invirt-console.git] / debian / invirt-console-server.init
1 #!/bin/bash
2 ### BEGIN INIT INFO
3 # Provides:          invirt-console-server
4 # Required-Start:    $local_fs $remote_fs
5 # Required-Stop:     $local_fs $remote_fs
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: Invirt console proxy server
9 # Description:       
10 ### END INIT INFO
11
12 # Author: Invirt project <invirt@mit.edu>
13
14 # Do NOT "set -e"
15
16 # PATH should only include /usr/* if it runs after the mountnfs.sh script
17 PATH=/sbin:/usr/sbin:/bin:/usr/bin
18 DESC="the Invirt console server"
19 NAME=invirt-console-server
20 DAEMON=/usr/bin/invirt-consolefs
21 MOUNTPOINT="/consolefs"
22 DAEMON_ARGS="-f $MOUNTPOINT"
23 PIDFILE=/var/run/$NAME.pid
24 SCRIPTNAME=/etc/init.d/$NAME
25
26 # Exit if the package is not installed
27 [ -x "$DAEMON" ] || exit 0
28
29 . /lib/init/std-init.sh
30
31 gen_config()
32 {
33     for i in /etc/conserver/invirt-hosts.cf \
34              /etc/remctl/acl/invirt-console-server \
35              /etc/issue.net.no_tkt \
36              /etc/nss-pgsql.conf \
37              ; do
38         mako-render $i.mako > $i
39     done
40 }
41
42 #
43 # Function that starts the daemon/service
44 #
45 do_start()
46 {
47     # Return
48     #   0 if daemon has been started
49     #   1 if daemon was already running
50     #   2 if daemon could not be started
51     
52     # Try to make sure fuse is setup
53     [ -e /dev/fuse ] || modprobe fuse || return 2
54     
55     if cat /proc/mounts | grep " $MOUNTPOINT " >/dev/null 2>&1; then
56         return 1
57     fi
58     
59     gen_config
60     
61     daemon -r -O daemon.info -E daemon.err -n $NAME -- $DAEMON $DAEMON_ARGS || return 2
62 }
63
64 #
65 # Function that stops the daemon/service
66 #
67 do_stop()
68 {
69     # Return
70     #   0 if daemon has been stopped
71     #   1 if daemon was already stopped
72     #   2 if daemon could not be stopped
73     #   other if a failure occurred
74     
75     if ! cat /proc/mounts | grep " $MOUNTPOINT " >/dev/null 2>&1; then
76         return 1
77     fi
78     
79     daemon --stop -n $NAME
80     RETVAL="$?"
81     [ "$RETVAL" = 2 ] && return 2
82     # Many daemons don't delete their pidfiles when they exit.
83     rm -f $PIDFILE
84 }
85
86 do_reload()
87 {
88     gen_config
89     invoke-rc.d conserver-server reload
90 }
91
92 std_init "$1"