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