1 #! /bin/bash 2 ### BEGIN INIT INFO 3 # Provides: kolab-server 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 Server daemon 9 # Description: The Kolab server is a server process which synchronizes 10 # LDAP, SQL and other authentication databases with Cyrus IMAP, 11 # Dovecot or other IMAP servers. 12 ### END INIT INFO 13 14 PATH=/sbin:/usr/sbin:/bin:/usr/bin 15 DESC="The Kolab server synchronizes LDAP, SQL and other authentication databases with Cyrus IMAP, Dovecot or other IMAP servers." # Introduce a short description here 16 NAME=kolabd # Introduce the short server's name here 17 DAEMON=/usr/sbin/kolabd # Introduce the server's location here 18 USER="kolab" 19 GROUP="kolab-n" 20 DAEMON_ARGS="--fork --user $USER" # Arguments to run the daemon with 21 FLAGS="-l warning" 22 PIDFILE=/run/$NAME/$NAME.pid 23 LOCKFILE=/run/lock/$NAME 24 DEFAULTSFILE=/etc/default/$NAME 25 SCRIPTNAME=/etc/init.d/$NAME 26 27 # Read configuration variable file if it is present 28 [ -r /etc/default/kolab-server ] && . /etc/default/kolab-server 29 30 # Load the VERBOSE setting and other rcS variables 31 . /lib/init/vars.sh 32 33 # Define LSB log_* functions. 34 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. 35 . /lib/lsb/init-functions 36 37 # 38 # Function that starts the daemon/service 39 # 40 do_start() 41 { 42 # Return 43 # 0 if daemon has been started 44 # 1 if daemon was already running 45 # 2 if daemon could not be started 46 47 # If the daemon is not enabled, give the user a warning and stop. 48 if [ "$START" != "yes" ]; then 49 log_warning_msg "To enable $NAME, edit $DEFAULTSFILE and set START=yes" 50 return 0 51 fi 52 53 if [ ! -d /run/$NAME ]; then 54 mkdir /run/$NAME 55 fi 56 chown $USER:$GROUP /run/$NAME 57 58 start-stop-daemon \ 59 --start \ 60 --quiet \ 61 --startas $DAEMON \ 62 --name $NAME \ 63 --test > /dev/null \ 64 || return 1 65 start-stop-daemon \ 66 --start \ 67 --quiet \ 68 --exec $DAEMON \ 69 --name $NAME \ 70 -- $FLAGS $DAEMON_ARGS --pid-file $PIDFILE \ 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 --user $USER \ 93 --startas $DAEMON \ 94 --name $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 --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|status|restart|force-reload}" >&2 151 exit 3 152 ;; 153 esac 154 :