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