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