4
# Required-Start: $local_fs $remote_fs $syslog $network $time
5
# Required-Stop: $local_fs $remote_fs $syslog $network
6
# Default-Start: 2 3 4 5
8
# Short-Description: Starts and stops the masqmail daemon
9
# Description: The masqmail daemon listens for incoming SMTP connections
10
# and processes its mail queue in regular intervals.
13
# DON'T EDIT THIS FILE, use /etc/default/masqmail!
15
INIT_SMTP_DAEMON="false"
16
INIT_QUEUE_DAEMON="false"
18
PATH=/sbin:/usr/sbin:/bin:/usr/bin
19
DESC="Mail Transfer Agent (MTA)"
21
DAEMON=/usr/sbin/$NAME
23
RUN_DIR=/var/run/$NAME
24
PIDFILE=$RUN_DIR/$NAME.pid
25
SCRIPTNAME=/etc/init.d/$NAME
27
# Exit if the package is not installed
28
[ -x "$DAEMON" ] || exit 0
30
# Read configuration variable file if it is present
31
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
32
QUEUE_DAEMON_IVAL=${QUEUE_DAEMON_IVAL:--q10m}
34
# Load the VERBOSE setting and other rcS variables
37
# Define LSB log_* functions.
38
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
39
# and status_of_proc is working.
40
. /lib/lsb/init-functions
42
# Create /var/run/masqmail if /var/run/ is a tmpfs.
45
[ "$INIT_SMTP_DAEMON" = true ] && DAEMON_ARGS="$DAEMON_ARGS -bd"
46
[ "$INIT_QUEUE_DAEMON" = true ] && DAEMON_ARGS="$DAEMON_ARGS $QUEUE_DAEMON_IVAL"
49
# Function that starts the daemon/service
54
# 0 if daemon has been started
55
# 1 if daemon was already running
56
# 2 if daemon could not be started
57
# 3 if daemon should not be started
59
if [ "$INIT_SMTP_DAEMON" != true -a "$INIT_QUEUE_DAEMON" != true ]; then
60
[ "$VERBOSE" != no ] && log_progress_msg "daemons are disabled. See /etc/default/$NAME"
64
if [ "$INIT_SMTP_DAEMON" = true ]; then
65
# give a hint we start the smtp daemon
66
[ "$VERBOSE" != no ] && log_progress_msg "listen"
69
if [ "$INIT_QUEUE_DAEMON" = true ]; then
70
# give a hint we start the queue daemon
71
[ "$VERBOSE" != no ] && log_progress_msg "queue ($QUEUE_DAEMON_IVAL)"
74
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
76
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
79
# Add code here, if necessary, that waits for the process to be ready
80
# to handle requests from services started subsequently which depend
81
# on this one. As a last resort, sleep for some time.
85
# Function that stops the daemon/service
90
# 0 if daemon has been stopped
91
# 1 if daemon was already stopped
92
# 2 if daemon could not be stopped
93
# other if a failure occurred
94
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
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.
111
# Function that sends a SIGHUP to the daemon/service
115
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
121
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
125
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
126
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
127
3) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
131
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
134
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
135
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
139
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
142
log_daemon_msg "Reloading $DESC" "$NAME"
147
log_daemon_msg "Restarting $DESC" "$NAME"
154
1) log_end_msg 1 ;; # Old process is still running
155
*) log_end_msg 1 ;; # Failed to start
165
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2