summaryrefslogtreecommitdiff
path: root/debian/sendmail.init.d
diff options
context:
space:
mode:
Diffstat (limited to 'debian/sendmail.init.d')
-rw-r--r--debian/sendmail.init.d169
1 files changed, 169 insertions, 0 deletions
diff --git a/debian/sendmail.init.d b/debian/sendmail.init.d
new file mode 100644
index 0000000..0788bda
--- /dev/null
+++ b/debian/sendmail.init.d
@@ -0,0 +1,169 @@
+#!/bin/sh
+set -e
+# Start or stop sendmail
+#
+# Robert Leslie <rob@mars.org>
+# Johnie Ingram <johnie@netgod.net>
+# David Rocher <rocher@mail.dotcom.fr>
+# Richard Nelson <cowboy@debain.org>
+
+# How often to run the queue
+Q="10m"
+
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+DAEMON=/usr/sbin/sendmail
+COMMAND=/usr/sbin/sendmail
+PIDFILE=/var/run/sendmail.pid
+QUEUE=/var/spool/mqueue
+START_CMD="start-stop-daemon \
+ --pidfile $PIDFILE \
+ --exec $DAEMON \
+ --startas $COMMAND \
+ --start"
+STOP_CMD="start-stop-daemon \
+ --pidfile $PIDFILE \
+ --stop"
+NAME=sendmail
+FLAGS="defaults 50"
+
+# Support for coexistance with smtpd package
+SMTPD=/usr/sbin/smtpd
+
+test -x $DAEMON -a -d /usr/share/sendmail || exit 0
+
+#
+# Clean sendmail queues (somewhat)
+queue_clean () {
+ # remove lock files left because of kill/crash
+ # rm -f $QUEUE/[lnx]f* doesn't work with a plethora of files ;-{
+ for i in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z; do
+ rm -f [lnx]f${i}*
+ done
+ # remove zero length qf files
+ for qffile in $QUEUE/qf*; do
+ if [ -r "$qffile" -a ! -s "$qffile" ]; then
+ echo -n "<zero: $qffile> "
+ rm -f "$qffile"
+ fi
+ done
+ # rename tf files to be qf if the qf does not exist
+ for tffile in $QUEUE/tf*; do
+ qffile=`echo "$tffile" | sed 's/t/q/'`
+ if [ -r "$tffile" -a ! -f "$qffile" ]; then
+ echo -n "<recovering: $tffile> "
+ mv "$tffile" "$qffile"
+ elif [ -f "$tffile" ]; then
+ echo -n "<extra: $tffile> "
+ rm -f "$tffile"
+ fi
+ done
+ # remove df files with no corresponding qf files
+ for dffile in $QUEUE/df*; do
+ qffile=`echo "$dffile" | sed 's/d/q/'`
+ if [ -r "$dffile" -a ! -f "$qffile" ]; then
+ echo -n "<incomplete: $dffile> "
+ mv "$dffile" `echo $dffile | sed 's/d/D/'`
+ fi
+ done
+ # announce files that have been saved during disaster recovery
+ for xffile in $QUEUE/[A-Z]f*; do
+ if [ -f "$xffile" ]; then
+ echo -n "<panic: $xffile> "
+ fi
+ done
+ }
+
+#
+# enhanced sendmail startup
+start() {
+ # cleanup queues
+ queue_clean;
+
+ # Skip daemon run for the following:
+ # * sendmail hasn't been configured
+ # * smptd, a firewall frontend for sendmail, is installed
+ # * If running a nullclient
+ if [ ! -s /etc/mail/sendmail.mc ]; then
+ echo "sendmail has not been configured, not started."
+ echo "To configure sendmail, type sendmailconfig"
+ exit 0
+ elif [ -x $SMTPD ] || \
+ egrep -qe "^[[:space:]]*FEATURE(nullclient)" \
+ /etc/mail/sendmail.mc \
+ ; then
+ echo "sendmail daemon not needed, not started."
+ exit 0
+ fi
+ # Ok, really start the puppy
+ cd /var/lib/sendmail
+ $START_CMD -- -bd -q"$Q"
+ }
+
+#
+# enhanced sendmail shutdown
+stop () {
+ $STOP_CMD --quiet --oknodo > /dev/null
+ #
+ # Now we have to wait until sendmail has _really_ stopped.
+ #
+ sleep 2
+ if $STOP_CMD --quiet > /dev/null; then
+ echo -n "Waiting ."
+ cnt=0
+ while $STOP_CMD --quiet > /dev/null; do
+ cnt=`expr $cnt + 1`
+ if [ $cnt -gt 60 ]; then
+ #
+ # Waited 120 seconds now. Fail.
+ #
+ echo -n " Failed "
+ break
+ fi
+ sleep 2
+ echo -n "."
+ done
+ echo -n " Done "
+ fi
+ }
+
+case "$1" in
+ start)
+ echo -n "Starting mail transport agent: "
+ start
+ echo "$NAME."
+ ;;
+
+ stop)
+ echo -n "Stopping mail transport agent: "
+ stop
+ echo "$NAME."
+ ;;
+
+ restart)
+ $0 stop
+ $0 start
+ ;;
+
+ reload)
+ echo -n "Reloading $NAME configuration..."
+ $STOP_CMD --signal HUP
+ echo "done."
+ ;;
+
+ force-reload)
+ $0 reload
+ ;;
+
+ debug)
+ echo -n "Dumping $NAME state..."
+ $STOP_CMD --signal USR1
+ echo "done."
+ ;;
+
+ *)
+ echo "Usage: /etc/init.d/sendmail {start|stop|restart|reload|force-reload|debug}"
+ exit 1
+ ;;
+esac
+
+exit 0