#!/bin/sh ### BEGIN INIT INFO # Provides: dovecot # Required-Start: $syslog # Required-Stop: $syslog # Should-Start: $local_fs $time ntp # Should-Stop: $local_fs # Default-Start: 3 # Default-Stop: 0 1 6 # Short-Description: Dovecot init script # Description: Init script for dovecot services ### END INIT INFO # Do NOT "set -e" PATH=/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="IMAP/POP3 mail server" NAME=dovecot DAEMON=/usr/sbin/dovecot DAEMON_ARGS="" SCRIPTNAME=/etc/init.d/$NAME CONF=/etc/dovecot/${NAME}.conf # Exit if the package is not installed [ -x "$DAEMON" ] || exit 0 # Exit if the configuration file doesn't exist [ -f "$CONF" ] || exit 0 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions # cong file readable? if [ ! -r ${CONF} ] then log_daemon_msg "${CONF}: not readable" "$NAME" && log_end_msg 1; exit 1; fi ### ------------------------------------------------------------------------- ### start/stop and failure message color output ### ------------------------------------------------------------------------- COLOR_RED='\033[1;31m' COLOR_NRM='\033[0;39m' log_end_msg_new () { echo -en "\\033[300C\\033[8D" if [ "$1" -eq 0 ] then echo " [ OK ]" elif [ "$1" = "9" ] then echo " disabled" else echo -e " [${COLOR_RED}fail${COLOR_NRM}]" fi } ### ------------------------------------------------------------------------- ### start/stop ### ------------------------------------------------------------------------- # determine the location of the PID file # overide by setting base_dir in conf file or PIDBASE in /etc/defaults/$NAME PIDBASE=${PIDBASE:-`sed -r "s/^[ \t]*base_dir[ \t]*=[ \t]*([^ \t]*)/\1/;t;d" ${CONF}`} PIDFILE=${PIDBASE:-/var/run/dovecot/}master.pid # # Function that starts the daemon/service # do_start() { start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS || return 2 } # # Function that stops the daemon/service # do_stop() { # Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name ${DAEMON##*/} RETVAL="$?" [ "$RETVAL" = 2 ] && return 2 # Wait for children to finish too if this is a daemon that forks # and if the daemon is only ever run from this initscript. # If the above conditions are not satisfied then add some other code # that waits for the process to drop all resources that could be # needed by services started subsequently. A last resort is to # sleep for some time. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --pidfile $PIDFILE --name ${DAEMON##*/} [ "$?" = 2 ] && return 2 # Many daemons don't delete their pidfiles when they exit. rm -f $PIDFILE return "$RETVAL" } # # Function that sends a SIGHUP to the daemon/service # do_reload() { # # If the daemon can reload its configuration without # restarting (for example, when it is sent a SIGHUP), # then implement that here. # start-stop-daemon --stop --signal USR1 --quiet --pidfile $PIDFILE --name $NAME return 0 } case "$1" in start) if start-stop-daemon --test --start --exec $DAEMON >/dev/null then log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0|1) log_end_msg 0 ;; 2) log_end_msg 1 ;; esac fi ;; stop) if ! start-stop-daemon --test --start --exec $DAEMON >/dev/null then log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) log_end_msg 0 ;; 2) log_end_msg 1 ;; esac fi ;; reload|force-reload) log_daemon_msg "Reloading $DESC" "$NAME" do_reload log_end_msg $? ;; restart) # If the "reload" option is implemented then remove the # 'force-reload' alias log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) # Failed to stop log_end_msg 1 ;; esac ;; status) echo -n " * POP3/IMAP dovecot" if start-stop-daemon --test --start --exec $DAEMON >/dev/null then log_end_msg_new 1 else log_end_msg_new 0 fi ;; *) echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|status}" >&2 exit 3 ;; esac exit 0