3986a84afaa09904ef048463a125844b821a0c9d
[invirt/packages/invirt-console.git] / debian / sipb-xen-console.init
1 #!/bin/bash
2 ### BEGIN INIT INFO
3 # Provides:          sipb-xen-console
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: sipb-xen Console Server homedir filesystem
9 # Description:       
10 ### END INIT INFO
11
12 # Author: SIPB Xen Project <sipb-xen@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 sipb-xen console server"
19 NAME=sipb-xen-console
20 DAEMON=/usr/bin/sipb-xen-consolefs
21 DAEMON_ARGS="/consolefs"
22 PIDFILE=/var/run/$NAME.pid
23 SCRIPTNAME=/etc/init.d/$NAME
24
25 # Exit if the package is not installed
26 [ -x "$DAEMON" ] || exit 0
27
28 # Read configuration variable file if it is present
29 [ -r /etc/default/$NAME ] && . /etc/default/$NAME
30
31 # Load the VERBOSE setting and other rcS variables
32 . /lib/init/vars.sh
33
34 # Define LSB log_* functions.
35 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
36 . /lib/lsb/init-functions
37
38 gen_config()
39 {
40     {
41         for i in $(invirt-getconf --ls hosts); do
42             local hostname=$(invirt-getconf hosts.$i.hostname)
43             echo "#include /etc/conserver/conf.d/$hostname"
44         done
45     } > /etc/conserver/invirt-hosts.cf
46     local realm=$(invirt-getconf authn.0.realm)
47     {
48         for i in $(invirt-getconf --ls hosts); do
49             local hostname=$(invirt-getconf hosts.$i.hostname)
50             echo "host/$hostname@$realm"
51         done
52     } > /etc/remctl/acl/invirt-console
53
54     mako-render /etc/nss-pgsql.conf.mako > /etc/nss-pgsql.conf
55
56     fmt > /etc/issue.net.no_tkt << EOF
57 You must login to the $(invirt-getconf console.hostname) console server using
58 Kerberos tickets, but your ssh client did not pass a valid ticket to the
59 console server.
60 EOF
61 }
62
63 #
64 # Function that starts the daemon/service
65 #
66 do_start()
67 {
68         # Return
69         #   0 if daemon has been started
70         #   1 if daemon was already running
71         #   2 if daemon could not be started
72         modprobe fuse
73         gen_config
74         daemon --running -n $NAME && return 1
75         daemon -r -O daemon.info -E daemon.err -n $NAME -U $DAEMON $DAEMON_ARGS || return 2
76 }
77
78 #
79 # Function that stops the daemon/service
80 #
81 do_stop()
82 {
83         # Return
84         #   0 if daemon has been stopped
85         #   1 if daemon was already stopped
86         #   2 if daemon could not be stopped
87         #   other if a failure occurred
88         daemon --stop -n $NAME
89         RETVAL="$?"
90         [ "$RETVAL" = 2 ] && return 2
91         # Many daemons don't delete their pidfiles when they exit.
92         rm -f $PIDFILE
93         umount "$DAEMON_ARGS"
94         return "$RETVAL"
95 }
96
97 do_reload()
98 {
99         gen_config
100         /etc/init.d/conserver-server reload
101 }
102
103 case "$1" in
104   start)
105         [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
106         do_start
107         case "$?" in
108                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
109                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
110         esac
111         ;;
112   stop)
113         [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
114         do_stop
115         case "$?" in
116                 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
117                 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
118         esac
119         ;;
120   reload|force-reload)
121         log_daemon_msg "Reloading $DESC" "$NAME"
122         do_reload
123         log_end_msg $?
124         ;;
125   restart)
126         log_daemon_msg "Restarting $DESC" "$NAME"
127         do_stop
128         case "$?" in
129           0|1)
130                 do_start
131                 case "$?" in
132                         0) log_end_msg 0 ;;
133                         1) log_end_msg 1 ;; # Old process is still running
134                         *) log_end_msg 1 ;; # Failed to start
135                 esac
136                 ;;
137           *)
138                 # Failed to stop
139                 log_end_msg 1
140                 ;;
141         esac
142         ;;
143   *)
144         echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
145         exit 3
146         ;;
147 esac
148
149 :