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