[843] | 1 | #!/bin/bash |
---|
[335] | 2 | ### BEGIN INIT INFO |
---|
[1200] | 3 | # Provides: invirt-console-server |
---|
[335] | 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 |
---|
[1200] | 8 | # Short-Description: Invirt console proxy server |
---|
[335] | 9 | # Description: |
---|
| 10 | ### END INIT INFO |
---|
| 11 | |
---|
[1222] | 12 | # Author: Invirt project <invirt@mit.edu> |
---|
[335] | 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 |
---|
[1200] | 18 | DESC="the Invirt console server" |
---|
| 19 | NAME=invirt-console-server |
---|
| 20 | DAEMON=/usr/bin/invirt-consolefs |
---|
[1741] | 21 | MOUNTPOINT="/consolefs" |
---|
| 22 | DAEMON_ARGS="-f $MOUNTPOINT" |
---|
[335] | 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 | # Read configuration variable file if it is present |
---|
| 30 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME |
---|
| 31 | |
---|
| 32 | # Load the VERBOSE setting and other rcS variables |
---|
| 33 | . /lib/init/vars.sh |
---|
| 34 | |
---|
| 35 | # Define LSB log_* functions. |
---|
| 36 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
---|
| 37 | . /lib/lsb/init-functions |
---|
| 38 | |
---|
[699] | 39 | gen_config() |
---|
| 40 | { |
---|
[888] | 41 | for i in /etc/conserver/invirt-hosts.cf \ |
---|
[1200] | 42 | /etc/remctl/acl/invirt-console-server \ |
---|
[888] | 43 | /etc/issue.net.no_tkt \ |
---|
| 44 | /etc/nss-pgsql.conf \ |
---|
| 45 | ; do |
---|
| 46 | mako-render $i.mako > $i |
---|
| 47 | done |
---|
[699] | 48 | } |
---|
| 49 | |
---|
[335] | 50 | # |
---|
| 51 | # Function that starts the daemon/service |
---|
| 52 | # |
---|
| 53 | do_start() |
---|
| 54 | { |
---|
[1740] | 55 | # Return |
---|
| 56 | # 0 if daemon has been started |
---|
| 57 | # 1 if daemon was already running |
---|
| 58 | # 2 if daemon could not be started |
---|
[1741] | 59 | |
---|
| 60 | # Try to make sure fuse is setup |
---|
| 61 | [ -e /dev/fuse ] || modprobe fuse || return 2 |
---|
| 62 | |
---|
| 63 | if cat /proc/mounts | grep " $MOUNTPOINT " >/dev/null 2>&1; then |
---|
| 64 | return 1 |
---|
| 65 | fi |
---|
| 66 | |
---|
[1740] | 67 | gen_config |
---|
[1741] | 68 | |
---|
| 69 | daemon -r -O daemon.info -E daemon.err -n $NAME -- $DAEMON $DAEMON_ARGS || return 2 |
---|
[335] | 70 | } |
---|
| 71 | |
---|
| 72 | # |
---|
| 73 | # Function that stops the daemon/service |
---|
| 74 | # |
---|
| 75 | do_stop() |
---|
| 76 | { |
---|
[1740] | 77 | # Return |
---|
| 78 | # 0 if daemon has been stopped |
---|
| 79 | # 1 if daemon was already stopped |
---|
| 80 | # 2 if daemon could not be stopped |
---|
| 81 | # other if a failure occurred |
---|
[1741] | 82 | |
---|
| 83 | if ! cat /proc/mounts | grep " $MOUNTPOINT " >/dev/null 2>&1; then |
---|
| 84 | return 1 |
---|
| 85 | fi |
---|
| 86 | |
---|
[1740] | 87 | daemon --stop -n $NAME |
---|
| 88 | RETVAL="$?" |
---|
| 89 | [ "$RETVAL" = 2 ] && return 2 |
---|
| 90 | # Many daemons don't delete their pidfiles when they exit. |
---|
| 91 | rm -f $PIDFILE |
---|
[335] | 92 | } |
---|
| 93 | |
---|
[699] | 94 | do_reload() |
---|
| 95 | { |
---|
[1740] | 96 | gen_config |
---|
| 97 | invoke-rc.d conserver-server reload |
---|
[699] | 98 | } |
---|
| 99 | |
---|
[335] | 100 | case "$1" in |
---|
| 101 | start) |
---|
[1740] | 102 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
---|
| 103 | do_start |
---|
| 104 | case "$?" in |
---|
| 105 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
| 106 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
| 107 | esac |
---|
| 108 | ;; |
---|
[335] | 109 | stop) |
---|
[1740] | 110 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
---|
| 111 | do_stop |
---|
| 112 | case "$?" in |
---|
| 113 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
| 114 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
| 115 | esac |
---|
| 116 | ;; |
---|
[699] | 117 | reload|force-reload) |
---|
[1740] | 118 | log_daemon_msg "Reloading $DESC" "$NAME" |
---|
| 119 | do_reload |
---|
| 120 | log_end_msg $? |
---|
| 121 | ;; |
---|
[699] | 122 | restart) |
---|
[1740] | 123 | log_daemon_msg "Restarting $DESC" "$NAME" |
---|
| 124 | do_stop |
---|
| 125 | case "$?" in |
---|
| 126 | 0|1) |
---|
| 127 | do_start |
---|
| 128 | case "$?" in |
---|
| 129 | 0) log_end_msg 0 ;; |
---|
| 130 | 1) log_end_msg 1 ;; # Old process is still running |
---|
| 131 | *) log_end_msg 1 ;; # Failed to start |
---|
| 132 | esac |
---|
| 133 | ;; |
---|
| 134 | *) |
---|
| 135 | # Failed to stop |
---|
| 136 | log_end_msg 1 |
---|
| 137 | ;; |
---|
| 138 | esac |
---|
| 139 | ;; |
---|
[335] | 140 | *) |
---|
[1740] | 141 | echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 |
---|
| 142 | exit 3 |
---|
| 143 | ;; |
---|
[335] | 144 | esac |
---|
| 145 | |
---|
| 146 | : |
---|