[23178] | 1 | #! /bin/sh |
---|
| 2 | ### BEGIN INIT INFO |
---|
| 3 | # Provides: debathena-moira-update-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: Moira update_server |
---|
| 9 | # Description: The moira update_server program for taking updates from |
---|
| 10 | # moira |
---|
| 11 | ### END INIT INFO |
---|
| 12 | |
---|
| 13 | # Author: Evan Broder <broder@mit.edu> |
---|
| 14 | |
---|
| 15 | # Do NOT "set -e" |
---|
| 16 | |
---|
| 17 | # PATH should only include /usr/* if it runs after the mountnfs.sh script |
---|
| 18 | PATH=/usr/sbin:/usr/bin:/sbin:/bin |
---|
| 19 | DESC="Moira update_server" |
---|
| 20 | NAME=debathena-moira-update-server |
---|
| 21 | DAEMON=/usr/sbin/update_server |
---|
| 22 | DAEMON_ARGS="" |
---|
| 23 | SCRIPTNAME=/etc/init.d/$NAME |
---|
[24998] | 24 | ENABLED=false |
---|
[25046] | 25 | PIDFILE=/var/run/update_server.pid |
---|
[23178] | 26 | |
---|
| 27 | # Exit if the package is not installed |
---|
| 28 | [ -x "$DAEMON" ] || exit 0 |
---|
| 29 | |
---|
| 30 | # Read configuration variable file if it is present |
---|
| 31 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME |
---|
| 32 | |
---|
[24998] | 33 | # Exit if the daemon has not been enabled |
---|
| 34 | [ "$ENABLED" = true ] || exit 0 |
---|
| 35 | |
---|
[23178] | 36 | # Load the VERBOSE setting and other rcS variables |
---|
| 37 | [ -f /etc/default/rcS ] && . /etc/default/rcS |
---|
| 38 | |
---|
| 39 | # Define LSB log_* functions. |
---|
| 40 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
---|
| 41 | . /lib/lsb/init-functions |
---|
| 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 |
---|
[25053] | 51 | |
---|
[25054] | 52 | # Remove the following once #849 is fixed and update_server is |
---|
| 53 | # capable of writing its own pidfile |
---|
[25053] | 54 | PID="$(pgrep -f $DAEMON)" |
---|
| 55 | if [ -n "$PID" ]; then |
---|
[25055] | 56 | if ! [ -f "$PIDFILE" ]; then |
---|
| 57 | echo "$PID" > $PIDFILE |
---|
| 58 | elif [ "$(cat $PIDFILE)" != "$PID" ]; then |
---|
[25053] | 59 | rm -f $PIDFILE |
---|
| 60 | echo "$PID" > $PIDFILE |
---|
| 61 | fi |
---|
| 62 | fi |
---|
| 63 | start-stop-daemon --start --quiet --pidfile $PIDFILE \ |
---|
| 64 | --exec $DAEMON --test > /dev/null \ |
---|
[23178] | 65 | || return 1 |
---|
[25046] | 66 | start-stop-daemon --start --quiet --pidfile $PIDFILE \ |
---|
| 67 | --exec $DAEMON -- \ |
---|
[23178] | 68 | $DAEMON_ARGS \ |
---|
| 69 | || return 2 |
---|
[25054] | 70 | # Remove the following once #849 is fixed and update_server is |
---|
| 71 | # capable of writing its own pidfile |
---|
[25053] | 72 | sleep 1 |
---|
[25055] | 73 | # If we got here, we successfully started the daemon, |
---|
| 74 | # so overwrite the PID file |
---|
| 75 | rm -f $PIDFILE |
---|
[25053] | 76 | PID="$(pgrep -f $DAEMON)" |
---|
[25055] | 77 | echo "$PID" > $PIDFILE |
---|
[23178] | 78 | # Add code here, if necessary, that waits for the process to be ready |
---|
| 79 | # to handle requests from services started subsequently which depend |
---|
| 80 | # on this one. As a last resort, sleep for some time. |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | # |
---|
| 84 | # Function that stops the daemon/service |
---|
| 85 | # |
---|
| 86 | do_stop() |
---|
| 87 | { |
---|
| 88 | # Return |
---|
| 89 | # 0 if daemon has been stopped |
---|
| 90 | # 1 if daemon was already stopped |
---|
| 91 | # 2 if daemon could not be stopped |
---|
| 92 | # other if a failure occurred |
---|
[25046] | 93 | start-stop-daemon --stop --quiet --pidfile $PIDFILE |
---|
[23178] | 94 | RETVAL="$?" |
---|
| 95 | [ "$RETVAL" = 2 ] && return 2 |
---|
| 96 | # Wait for children to finish too if this is a daemon that forks |
---|
| 97 | # and if the daemon is only ever run from this initscript. |
---|
| 98 | # If the above conditions are not satisfied then add some other code |
---|
| 99 | # that waits for the process to drop all resources that could be |
---|
| 100 | # needed by services started subsequently. A last resort is to |
---|
| 101 | # sleep for some time. |
---|
[25053] | 102 | start-stop-daemon --stop --quiet --oknodo --retry=0/10/KILL/5 --exec $DAEMON |
---|
[23178] | 103 | [ "$?" = 2 ] && return 2 |
---|
| 104 | return "$RETVAL" |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | case "$1" in |
---|
| 108 | start) |
---|
| 109 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" |
---|
| 110 | do_start |
---|
| 111 | case "$?" in |
---|
| 112 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
| 113 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
| 114 | esac |
---|
| 115 | ;; |
---|
| 116 | stop) |
---|
| 117 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
---|
| 118 | do_stop |
---|
| 119 | case "$?" in |
---|
| 120 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
---|
| 121 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
---|
| 122 | esac |
---|
| 123 | ;; |
---|
| 124 | restart|force-reload) |
---|
| 125 | # |
---|
| 126 | # If the "reload" option is implemented then remove the |
---|
| 127 | # 'force-reload' alias |
---|
| 128 | # |
---|
| 129 | log_daemon_msg "Restarting $DESC" "$NAME" |
---|
| 130 | do_stop |
---|
| 131 | case "$?" in |
---|
| 132 | 0|1) |
---|
| 133 | do_start |
---|
| 134 | case "$?" in |
---|
| 135 | 0) log_end_msg 0 ;; |
---|
| 136 | 1) log_end_msg 1 ;; # Old process is still running |
---|
| 137 | *) log_end_msg 1 ;; # Failed to start |
---|
| 138 | esac |
---|
| 139 | ;; |
---|
| 140 | *) |
---|
| 141 | # Failed to stop |
---|
| 142 | log_end_msg 1 |
---|
| 143 | ;; |
---|
| 144 | esac |
---|
| 145 | ;; |
---|
| 146 | *) |
---|
| 147 | echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 |
---|
| 148 | exit 3 |
---|
| 149 | ;; |
---|
| 150 | esac |
---|
| 151 | |
---|
| 152 | : |
---|