paul@1 | 1 | #! /bin/bash |
paul@1 | 2 | # |
paul@1 | 3 | ### BEGIN INIT INFO |
paul@1 | 4 | # Provides: wallace |
paul@1 | 5 | # Default-Start: 2 3 4 5 |
paul@1 | 6 | # Default-Stop: 0 1 6 |
paul@1 | 7 | # Required-Start: $remote_fs $local_fs $network |
paul@1 | 8 | # Required-Stop: $remote_fs $local_fs $network |
paul@1 | 9 | # Short-Description: Start/Stop the Kolab Server daemon |
paul@1 | 10 | # Description: The Kolab Wallace server daemon is a content filtering daemon. |
paul@1 | 11 | ### END INIT INFO |
paul@1 | 12 | |
paul@1 | 13 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
paul@1 | 14 | DESC="The Kolab Wallace server daemon is a content filtering daemon" # Introduce a short description here |
paul@1 | 15 | NAME=wallace # Introduce the short server's name here |
paul@1 | 16 | PROG_NAME=wallaced |
paul@1 | 17 | DAEMON=/usr/sbin/$PROG_NAME # Introduce the server's location here |
paul@1 | 18 | DAEMON_ARGS="--fork -l warning" # Arguments to run the daemon with |
paul@1 | 19 | PIDFILE=/run//$PROG_NAME/$PROG_NAME.pid |
paul@1 | 20 | LOCKFILE=/run/lock/$PROG_NAME |
paul@1 | 21 | SCRIPTNAME=/etc/init.d/$NAME |
paul@1 | 22 | DEFAULTSFILE=/etc/default/$NAME |
paul@1 | 23 | USER="kolab" |
paul@1 | 24 | GROUP="kolab-n" |
paul@1 | 25 | |
paul@1 | 26 | # Read configuration variable file if it is present |
paul@1 | 27 | [ -r /etc/default/$NAME ] && . /etc/default/$NAME |
paul@1 | 28 | |
paul@1 | 29 | # Load the VERBOSE setting and other rcS variables |
paul@1 | 30 | . /lib/init/vars.sh |
paul@1 | 31 | |
paul@1 | 32 | # Define LSB log_* functions. |
paul@1 | 33 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
paul@1 | 34 | . /lib/lsb/init-functions |
paul@1 | 35 | |
paul@1 | 36 | # |
paul@1 | 37 | # Function that starts the daemon/service |
paul@1 | 38 | # |
paul@1 | 39 | do_start() |
paul@1 | 40 | { |
paul@1 | 41 | # Return |
paul@1 | 42 | # 0 if daemon has been started |
paul@1 | 43 | # 1 if daemon was already running |
paul@1 | 44 | # 2 if daemon could not be started |
paul@1 | 45 | |
paul@1 | 46 | # If the daemon is not enabled, give the user a warning and stop. |
paul@1 | 47 | if [ "$START" != "yes" ]; then |
paul@1 | 48 | log_warning_msg "To enable $NAME, edit $DEFAULTSFILE and set START=yes" |
paul@1 | 49 | return 0 |
paul@1 | 50 | fi |
paul@1 | 51 | |
paul@1 | 52 | # Make sure the pid directory is there |
paul@1 | 53 | if [ ! -d /run/$PROG_NAME ]; then |
paul@1 | 54 | mkdir /run/$PROG_NAME |
paul@1 | 55 | fi |
paul@1 | 56 | chown $USER:$GROUP /run/$PROG_NAME |
paul@1 | 57 | |
paul@1 | 58 | start-stop-daemon \ |
paul@1 | 59 | --start \ |
paul@1 | 60 | --quiet \ |
paul@1 | 61 | --pidfile $PIDFILE \ |
paul@1 | 62 | --startas $DAEMON \ |
paul@1 | 63 | --test > /dev/null \ |
paul@1 | 64 | || return 1 |
paul@1 | 65 | start-stop-daemon \ |
paul@1 | 66 | --start \ |
paul@1 | 67 | --quiet \ |
paul@1 | 68 | --pidfile $PIDFILE \ |
paul@1 | 69 | --startas $DAEMON \ |
paul@1 | 70 | -- $FLAGS $DAEMON_ARGS \ |
paul@1 | 71 | || return 2 |
paul@1 | 72 | # Add code here, if necessary, that waits for the process to be ready |
paul@1 | 73 | # to handle requests from services started subsequently which depend |
paul@1 | 74 | # on this one. As a last resort, sleep for some time. |
paul@1 | 75 | touch $LOCKFILE |
paul@1 | 76 | } |
paul@1 | 77 | |
paul@1 | 78 | # |
paul@1 | 79 | # Function that stops the daemon/service |
paul@1 | 80 | # |
paul@1 | 81 | do_stop() |
paul@1 | 82 | { |
paul@1 | 83 | # Return |
paul@1 | 84 | # 0 if daemon has been stopped |
paul@1 | 85 | # 1 if daemon was already stopped |
paul@1 | 86 | # 2 if daemon could not be stopped |
paul@1 | 87 | # other if a failure occurred |
paul@1 | 88 | start-stop-daemon \ |
paul@1 | 89 | --stop \ |
paul@1 | 90 | --quiet \ |
paul@1 | 91 | --retry=TERM/30/KILL/5 \ |
paul@1 | 92 | --startas $DAEMON \ |
paul@1 | 93 | --pidfile $PIDFILE \ |
paul@1 | 94 | --name $PROG_NAME |
paul@1 | 95 | RETVAL="$?" |
paul@1 | 96 | [ "$RETVAL" = 2 ] && return 2 |
paul@1 | 97 | # Wait for children to finish too if this is a daemon that forks |
paul@1 | 98 | # and if the daemon is only ever run from this initscript. |
paul@1 | 99 | # If the above conditions are not satisfied then add some other code |
paul@1 | 100 | # that waits for the process to drop all resources that could be |
paul@1 | 101 | # needed by services started subsequently. A last resort is to |
paul@1 | 102 | # sleep for some time. |
paul@1 | 103 | start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --user $USER --exec $DAEMON |
paul@1 | 104 | [ "$?" = 2 ] && return 2 |
paul@1 | 105 | # Many daemons don't delete their pidfiles when they exit. |
paul@1 | 106 | rm -f $PIDFILE |
paul@1 | 107 | rm -f $LOCKFILE |
paul@1 | 108 | return "$RETVAL" |
paul@1 | 109 | } |
paul@1 | 110 | |
paul@1 | 111 | case "$1" in |
paul@1 | 112 | start) |
paul@1 | 113 | [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME" |
paul@1 | 114 | do_start |
paul@1 | 115 | case "$?" in |
paul@1 | 116 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
paul@1 | 117 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
paul@1 | 118 | esac |
paul@1 | 119 | ;; |
paul@1 | 120 | stop) |
paul@1 | 121 | [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" |
paul@1 | 122 | do_stop |
paul@1 | 123 | case "$?" in |
paul@1 | 124 | 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; |
paul@1 | 125 | 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; |
paul@1 | 126 | esac |
paul@1 | 127 | ;; |
paul@1 | 128 | status) |
paul@1 | 129 | status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? |
paul@1 | 130 | ;; |
paul@1 | 131 | restart|force-reload) |
paul@1 | 132 | log_daemon_msg "Restarting $DESC" "$NAME" |
paul@1 | 133 | do_stop |
paul@1 | 134 | case "$?" in |
paul@1 | 135 | 0|1) |
paul@1 | 136 | do_start |
paul@1 | 137 | case "$?" in |
paul@1 | 138 | 0) log_end_msg 0 ;; |
paul@1 | 139 | 1) log_end_msg 1 ;; # Old process is still running |
paul@1 | 140 | *) log_end_msg 1 ;; # Failed to start |
paul@1 | 141 | esac |
paul@1 | 142 | ;; |
paul@1 | 143 | *) |
paul@1 | 144 | # Failed to stop |
paul@1 | 145 | log_end_msg 1 |
paul@1 | 146 | ;; |
paul@1 | 147 | esac |
paul@1 | 148 | ;; |
paul@1 | 149 | *) |
paul@1 | 150 | #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 |
paul@1 | 151 | echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 |
paul@1 | 152 | exit 3 |
paul@1 | 153 | ;; |
paul@1 | 154 | esac |
paul@1 | 155 | |
paul@1 | 156 | : |