[Pkg-Cyrus-imapd-Debian-devel] [SVN] r160 -
trunk/cyrus-imapd-2.2.12/debian/cyrus22-common.cyrus22.init
debian at incase.de
debian at incase.de
Mon Aug 29 15:56:21 UTC 2005
Author: sven
Date: Mon Aug 29 17:56:20 2005
New Revision: 160
URL: https://mail.incase.de/viewcvs?root=cyrus22?view=rev&rev=160
Log:
Rework parts of init script to make it as much LSB 3.0 compliant as possible. This required making the server running tests not to rely on the pid file.
Modified:
trunk/cyrus-imapd-2.2.12/debian/cyrus22-common.cyrus22.init
Modified: trunk/cyrus-imapd-2.2.12/debian/cyrus22-common.cyrus22.init
URL: https://mail.incase.de/viewcvs?root=cyrus22/trunk/cyrus-imapd-2.2.12/debian/cyrus22-common.cyrus22.init?view=diff&rev=160&p1=trunk/cyrus-imapd-2.2.12/debian/cyrus22-common.cyrus22.init&r1=159&p2=trunk/cyrus-imapd-2.2.12/debian/cyrus22-common.cyrus22.init&r2=160
==============================================================================
--- trunk/cyrus-imapd-2.2.12/debian/cyrus22-common.cyrus22.init (original)
+++ trunk/cyrus-imapd-2.2.12/debian/cyrus22-common.cyrus22.init Mon Aug 29 17:56:20 2005
@@ -1,9 +1,23 @@
#! /bin/sh
#
-# cyrus22 /etc/init.d/ script for cyrus2 IMAPd
-# This file manages the Cyrus IMAPd master process.
+### BEGIN INIT INFO
+# Provides: cyrus22-common
+# Required-Start: $syslog $network
+# Required-Stop: $syslog $network
+# Default-Start: 2 3 4 5
+# Default-Stop: S 0 1 6
+# Short-Description: common init system for cyrus22 IMAP/POP3 daemons.
+# Description: common init system for cyrus22 IMAP/POP3 daemons.
+# start central cyrus22 master process, which can
+# then start various services depending on configuration.
+# Typically starts IMAP and POP3 daemons, but might also
+# start an NNTP daemon and various helper daemons for
+# distributed mail/news storage systems (high-performance
+# and/or high-reliability setups).
+### END INIT INFO
#
-# Copr. 2001 by Henrique de Moraes Holschuh <hmh at debian.org>
+# Copyright 2001-2005 by Henrique de Moraes Holschuh <hmh at debian.org>
+# Various modifications done by Sven Mueller <debian at incase.de>
# Distributed under the GPL version 2
#
# $Id$
@@ -64,6 +78,28 @@
|| missingstatoverride /var/run/cyrus/socket
[ -z "$dir" ] \
|| createdir $dir
+}
+
+checkstatus () {
+ if [ ! -f /var/run/${NAME}.pid ]; then
+ # using [c] in the grep avoids catching the grep
+ # process itself
+ if ps auxww | grep -qE 'usr/sbin/[c]yrmaster' ; then
+ # Damn, PID file doesn't exist, but cyrmaster process
+ # exists. Though strictly speaking, we should not
+ # do this, reconstruct the PID file here.
+ pidof /usr/sbin/cyrmaster > /var/run/${NAME}.pid
+ return 0
+ fi
+ fi
+ if kill -0 `cat /var/run/${NAME}.pid`; then
+ return 0
+ else
+ return 1
+ fi
+ # this point should never be reached, return unknown status if it
+ # is anyway
+ return 4
}
case "$1" in
@@ -76,7 +112,7 @@
echo "$0: at /usr/share/doc/cyrus22-common/UPGRADE.Debian" 1>&2
echo
echo "$0: Cyrmaster not started."
- exit 2
+ exit 6
}
# Verify consistency of database backends
[ -f /usr/lib/cyrus/cyrus-db-types.active ] && {
@@ -93,20 +129,21 @@
echo "$0: for instructions." 1>&2
echo
echo "$0: Cyrmaster not started."
- exit 2
+ exit 6
}
}
echo -n "Starting ${DESC}: "
fixdirs
+ if check_status ; then
+ echo "${DAEMON} already running."
+ exit 0
+ fi
if start-stop-daemon ${START} >/dev/null 2>&1 ; then
echo "$NAME."
else
- if start-stop-daemon --test ${START} >/dev/null 2>&1; then
+ if !check_status ; then
echo "(failed)."
exit 1
- else
- echo "${DAEMON} already running."
- exit 0
fi
fi
;;
@@ -115,25 +152,37 @@
if start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
--quiet --startas $DAEMON >/dev/null 2>&1 ; then
echo "$NAME."
- else
- echo "(failed)."
+ exit 0
+ else
+ # process running?
+ if check_status; then
+ # Yes, report failure.
+ echo "(failed)."
+ exit 1
+ else
+ # No, return as if stopped a running process
+ # successfully.
+ echo "."
+ exit 0
+ fi
fi
;;
reload|force-reload)
echo "Reloading $DESC configuration files."
- start-stop-daemon --stop --signal 1 --quiet \
- --pidfile /var/run/$NAME.pid --exec $DAEMON >/dev/null 2>&1
+ if start-stop-daemon --stop --signal 1 --quiet \
+ --pidfile /var/run/$NAME.pid --exec $DAEMON >/dev/null 2>&1 ; then
+ exit 0
+ else
+ exit 1
+ fi
;;
restart)
$0 stop && {
echo -n "Waiting for complete shutdown..."
i=5
while [ $i -gt 0 ] ; do
- if start-stop-daemon --start --test \
- --pidfile /var/run/$NAME.pid \
- --exec $DAEMON >/dev/null 2>&1 ; then
- break
- fi
+ # exit look when server is not running
+ check_status || break
sleep 2s
i=$(($i - 1))
echo -n "."
@@ -147,6 +196,20 @@
}
exec $0 start
;;
+ status)
+ check_status
+ exit $?
+ ;;
+ try-restart)
+ check_status
+ if [ "$?" -eq 0 ]; then
+ exec $0 restart
+ else
+ # LSB says to return 0 in try-restart if the service is
+ # not running.
+ exit 0
+ fi
+ ;;
*)
echo "Usage: $0 {start|stop|restart|reload|force-reload}" 1>&2
exit 1
More information about the Pkg-Cyrus-imapd-Debian-devel
mailing list