~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/masqmail

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
### BEGIN INIT INFO
3
 
# Provides:          masqmail
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
7
 
# Default-Stop:      0 1 6
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.
11
 
### END INIT INFO
12
 
 
13
 
# DON'T EDIT THIS FILE, use /etc/default/masqmail!
14
 
 
15
 
INIT_SMTP_DAEMON="false"
16
 
INIT_QUEUE_DAEMON="false"
17
 
 
18
 
PATH=/sbin:/usr/sbin:/bin:/usr/bin
19
 
DESC="Mail Transfer Agent (MTA)"
20
 
NAME=masqmail
21
 
DAEMON=/usr/sbin/$NAME
22
 
DAEMON_ARGS=
23
 
RUN_DIR=/var/run/$NAME
24
 
PIDFILE=$RUN_DIR/$NAME.pid
25
 
SCRIPTNAME=/etc/init.d/$NAME
26
 
 
27
 
# Exit if the package is not installed
28
 
[ -x "$DAEMON" ] || exit 0
29
 
 
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}
33
 
 
34
 
# Load the VERBOSE setting and other rcS variables
35
 
. /lib/init/vars.sh
36
 
 
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
41
 
 
42
 
# Create /var/run/masqmail if /var/run/ is a tmpfs.
43
 
mkdir -p $RUN_DIR
44
 
 
45
 
[ "$INIT_SMTP_DAEMON" = true ] && DAEMON_ARGS="$DAEMON_ARGS -bd"
46
 
[ "$INIT_QUEUE_DAEMON" = true ] && DAEMON_ARGS="$DAEMON_ARGS $QUEUE_DAEMON_IVAL"
47
 
 
48
 
#
49
 
# Function that starts the daemon/service
50
 
#
51
 
do_start()
52
 
{
53
 
        # Return
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
58
 
 
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"
61
 
                return 3
62
 
        fi
63
 
 
64
 
        if [ "$INIT_SMTP_DAEMON" = true ]; then
65
 
                # give a hint we start the smtp daemon
66
 
                [ "$VERBOSE" != no ] && log_progress_msg "listen"
67
 
        fi
68
 
 
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)"
72
 
        fi
73
 
 
74
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
75
 
                || return 1
76
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
77
 
                $DAEMON_ARGS \
78
 
                || return 2
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.
82
 
}
83
 
 
84
 
#
85
 
# Function that stops the daemon/service
86
 
#
87
 
do_stop()
88
 
{
89
 
        # Return
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
95
 
        RETVAL="$?"
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.
106
 
        rm -f $PIDFILE
107
 
        return "$RETVAL"
108
 
}
109
 
 
110
 
#
111
 
# Function that sends a SIGHUP to the daemon/service
112
 
#
113
 
do_reload()
114
 
{
115
 
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
116
 
        return 0
117
 
}
118
 
 
119
 
case "$1" in
120
 
  start)
121
 
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
122
 
        do_start
123
 
 
124
 
        case "$?" in
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 ;;
128
 
        esac
129
 
        ;;
130
 
  stop)
131
 
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
132
 
        do_stop
133
 
        case "$?" in
134
 
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
135
 
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
136
 
        esac
137
 
        ;;
138
 
  status)
139
 
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
140
 
       ;;
141
 
  reload|force-reload)
142
 
        log_daemon_msg "Reloading $DESC" "$NAME"
143
 
        do_reload
144
 
        log_end_msg $?
145
 
        ;;
146
 
  restart)
147
 
        log_daemon_msg "Restarting $DESC" "$NAME"
148
 
        do_stop
149
 
        case "$?" in
150
 
          0|1)
151
 
                do_start
152
 
                case "$?" in
153
 
                        0) log_end_msg 0 ;;
154
 
                        1) log_end_msg 1 ;; # Old process is still running
155
 
                        *) log_end_msg 1 ;; # Failed to start
156
 
                esac
157
 
                ;;
158
 
          *)
159
 
                # Failed to stop
160
 
                log_end_msg 1
161
 
                ;;
162
 
        esac
163
 
        ;;
164
 
  *)
165
 
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
166
 
        exit 3
167
 
        ;;
168
 
esac
169
 
 
170
 
: