File: init.d

package info (click to toggle)
mimedefang 2.57-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,764 kB
  • ctags: 520
  • sloc: ansic: 7,763; perl: 6,381; sh: 852; tcl: 693; makefile: 72; php: 19
file content (362 lines) | stat: -rw-r--r-- 10,336 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#!/bin/sh
#
# Generic start/stop script for MIMEDefang.  Should work on most
# flavors of UNIX.

unset HOME
RETVAL=0
prog='mimedefang'
SPOOLDIR='/var/spool/MIMEDefang'
PID="$SPOOLDIR/$prog.pid"
MXPID="$SPOOLDIR/$prog-multiplexor.pid"

# Is the program executable?  We search in /usr/bin and /usr/local/bin.

if [ -x /usr/bin/$prog ] ; then
    PROGDIR=/usr/bin
elif [ -x /usr/bin/$prog ] ; then
    PROGDIR=/usr/bin
elif [ -x /usr/local/bin/$prog ] ; then
    PROGDIR=/usr/local/bin
else
    exit 0
fi

# Locale should be set to "C" for generating valid date headers
LC_ALL=C
export LC_ALL

# The settings which follow are defaults.  You can override them by
# placing assignments in /etc/mail/mimedefang.conf

# The socket used by mimedefang to communicate with sendmail
# SOCKET=$SPOOLDIR/mimedefang.sock

# Run the multiplexor and filters as this user, not root.  RECOMMENDED
MX_USER=defang

# Syslog facility
# SYSLOG_FACILITY=mail

# If you want to keep spool directories around if the filter fails,
# set the next one to yes
# KEEP_FAILED_DIRECTORIES=no

# "yes" turns on the multiplexor relay checking function
# MX_RELAY_CHECK=no

# "yes" turns on the multiplexor HELO checking function
# MX_HELO_CHECK=no

# "yes" turns on the multiplexor sender checking function
# MX_SENDER_CHECK=no

# "yes" turns on the multiplexor recipient checking function
# MX_RECIPIENT_CHECK=no

# Set to yes if you want the multiplexor to log events to syslog
MX_LOG=yes

# Set to yes if you want to use an embedded Perl interpreter
# MX_EMBED_PERL=yes

# Set to full path of socket for Sendmail's SOCKETMAP map, if you
# want to use it with MIMEDefang
# MX_MAP_SOCKET=$SPOOLDIR/map.sock

# The multiplexor does not start all slaves at the same time.  Instead,
# it starts one slave every MX_SLAVE_DELAY seconds when the system is idle.
# (If the system is busy, the multiplexor starts slaves as incoming mail
# requires attention.)
# MX_SLAVE_DELAY=3

# The next setting is an absolute limit on slave activation.  The multiplexor
# will NEVER activate a slave within MX_MIN_SLAVE_DELAY seconds of another.
# The default of zero means that the multiplexor will activate slaves as
# quickly as necessary to keep up with incoming mail.
# MX_MIN_SLAVE_DELAY=0

# Set to yes if you want the multiplexor to log stats in
# /var/log/mimedefang/stats  The /var/log/mimedefang directory must
# exist and be writable by the user you're running MIMEDefang as.
# MX_STATS=no

# Number of slaves reserved for connections from loopback.  Use -1
# for default behaviour, 0 to allow loopback connections to queue,
# or >0 to reserve slaves for loopback connections
LOOPBACK_RESERVED_CONNECTIONS=-1

# Set to yes if you want the stats file flushed after each entry
# MX_FLUSH_STATS=no

# Set to yes if you want the multiplexor to log stats to syslog
# MX_STATS_SYSLOG=no

# The socket used by the multiplexor
# MX_SOCKET=$SPOOLDIR/mimedefang-multiplexor.sock

# Maximum # of requests a process handles
# MX_REQUESTS=200

# Minimum number of processes to keep.  The default of 0 is probably
# too low; we suggest 2 instead.
MX_MINIMUM=2

# Maximum number of processes to run (mail received while this many
# processes are running is rejected with a temporary failure, so be
# wary of how many emails you receive at a time).  This applies only
# if you DO use the multiplexor.  The default value of 2 is probably
# too low; we suggest 10 instead
MX_MAXIMUM=10

# Uncomment to log slave status; it will be logged every
# MX_LOG_SLAVE_STATUS_INTERVAL seconds
# MX_LOG_SLAVE_STATUS_INTERVAL=30

# Uncomment next line to have busy slaves send status updates to the
# multiplexor.  NOTE: Consumes one extra file descriptor per slave, plus
# a bit of CPU time.
# MX_STATUS_UPDATES=yes

# Limit slave processes' resident-set size to this many kilobytes.  Default
# is unlimited.
# MX_MAX_RSS=10000

# Limit total size of slave processes' memory space to this many kilobytes.
# Default is unlimited.
# MX_MAX_AS=30000

# If you want to use the "notification" facility, set the appropriate port.
# See the mimedefang-notify man page for details.
# MX_NOTIFIER=inet:4567

# Number of seconds a process should be idle before checking for
# minimum number and killed
# MX_IDLE=300

# Number of seconds a process is allowed to scan an email before it is
# considered dead.  The default is 30 seconds; we suggest 600.
MX_BUSY=600

# Extra sendmail macros to pass.  Actually, you can add any extra
# mimedefang options here...
# MD_EXTRA="-a auth_author"

# Multiplexor queue size -- default is 0 (no queueing)
# MX_QUEUE_SIZE=10

# Multiplexor queue timeout -- default is 30 seconds
# MX_QUEUE_TIMEOUT=30

# SUBFILTER specifies which filter rules file to use
# SUBFILTER=/etc/mimedefang-filter

# The contents of the "X-Scanned-By" header added to each mail.  Do
# not use the quote mark (') in this setting.  Setting it to "-"
# prevents the header from getting added at all.
# X_SCANNED_BY="MIMEDefang N.NN (www . roaringpenguin . com / mimedefang)"

# Source configuration
if [ -f /etc/mail/$prog.conf ] ; then
    . /etc/mail/$prog.conf
fi

# Make sure required vars are set
SOCKET=${SOCKET:=$SPOOLDIR/$prog.sock}
MX_SOCKET=${MX_SOCKET:=$SPOOLDIR/$prog-multiplexor.sock}

start_it() {
    if test -r $PID ; then
	if kill -0 `cat $PID` > /dev/null 2>&1 ; then
	    echo "mimedefang (`cat $PID`) seems to be running."
	    return 1
	fi
    fi
    if test -r $MXPID ; then
	if kill -0 `cat $MXPID` > /dev/null 2>&1 ; then
	    echo "mimedefang-multiplexor (`cat $MXPID`) seems to be running."
	    return 1
	fi
    fi

    printf "%-60s" "Starting $prog-multiplexor: "
    rm -f $MX_SOCKET > /dev/null 2>&1
    if [ "$MX_EMBED_PERL" = "yes" ] ; then
	EMBEDFLAG=-E
    else
	EMBEDFLAG=""
    fi
    $PROGDIR/$prog-multiplexor -p $MXPID \
	$EMBEDFLAG \
	`[ -n "$SPOOLDIR" ] && echo "-z $SPOOLDIR"` \
	`[ -n "$FILTER" ] && echo "-f $FILTER"` \
	`[ -n "$SYSLOG_FACILITY" ] && echo "-S $SYSLOG_FACILITY"` \
	`[ -n "$SUBFILTER" ] && echo "-F $SUBFILTER"` \
	`[ -n "$MX_MINIMUM" ] && echo "-m $MX_MINIMUM"` \
	`[ -n "$MX_MAXIMUM" ] && echo "-x $MX_MAXIMUM"` \
	`[ -n "$MX_MAP_SOCKET" ] && echo "-N $MX_MAP_SOCKET"` \
	`[ -n "$MX_LOG_SLAVE_STATUS_INTERVAL" ] && echo "-L $MX_LOG_SLAVE_STATUS_INTERVAL"` \
	`[ -n "$MX_USER" ] && echo "-U $MX_USER"` \
	`[ -n "$MX_IDLE" ] && echo "-i $MX_IDLE"` \
	`[ -n "$MX_BUSY" ] && echo "-b $MX_BUSY"` \
	`[ -n "$MX_REQUESTS" ] && echo "-r $MX_REQUESTS"` \
	`[ -n "$MX_SLAVE_DELAY" ] && echo "-w $MX_SLAVE_DELAY"` \
	`[ -n "$MX_MIN_SLAVE_DELAY" ] && echo "-W $MX_MIN_SLAVE_DELAY"` \
	`[ -n "$MX_MAX_RSS" ] && echo "-R $MX_MAX_RSS"` \
	`[ -n "$MX_MAX_AS" ] && echo "-M $MX_MAX_AS"` \
	`[ "$MX_LOG" = "yes" ] && echo "-l"` \
	`[ "$MX_STATS" = "yes" ] && echo "-t /var/log/mimedefang/stats"` \
	`[ "$MX_STATS" = "yes" -a "$MX_FLUSH_STATS" = "yes" ] && echo "-u"` \
	`[ "$MX_STATS_SYSLOG" = "yes" ] && echo "-T"` \
	`[ "$MX_STATUS_UPDATES" = "yes" ] && echo "-Z"` \
	`[ -n "$MX_QUEUE_SIZE" ] && echo "-q $MX_QUEUE_SIZE"` \
	`[ -n "$MX_QUEUE_TIMEOUT" ] && echo "-Q $MX_QUEUE_TIMEOUT"` \
	`[ -n "$MX_NOTIFIER" ] && echo "-O $MX_NOTIFIER"` \
	-s $MX_SOCKET
    RETVAL=$?
    if [ $RETVAL = 0 ] ; then
	echo "[  OK  ]"
    else
	echo "[FAILED]"
	return 1
    fi

    # Start mimedefang
    printf "%-60s" "Starting $prog: "
    rm -f $SOCKET > /dev/null 2>&1
    $PROGDIR/$prog -P $PID -R $LOOPBACK_RESERVED_CONNECTIONS \
	-m $MX_SOCKET \
	`[ -n "$SPOOLDIR" ] && echo "-z $SPOOLDIR"` \
	`[ -n "$MX_USER" ] && echo "-U $MX_USER"` \
	`[ -n "$SYSLOG_FACILITY" ] && echo "-S $SYSLOG_FACILITY"` \
	`[ "$MX_RELAY_CHECK" = "yes" ] && echo "-r"` \
	`[ "$MX_HELO_CHECK" = "yes" ] && echo "-H"` \
	`[ "$MX_SENDER_CHECK" = "yes" ] && echo "-s"` \
	`[ "$MX_RECIPIENT_CHECK" = "yes" ] && echo "-t"` \
	`[ "$KEEP_FAILED_DIRECTORIES" = "yes" ] && echo "-k"` \
	`[ "$MD_EXTRA" != "" ] && echo $MD_EXTRA` \
        "`[ -n "$X_SCANNED_BY" ] && \
	        ( [ "$X_SCANNED_BY" = "-" ] && \
		        echo "-X" || echo "-x$X_SCANNED_BY" )`" \
	`[ "$ALLOW_NEW_CONNECTIONS_TO_QUEUE" = "yes" ] && echo "-q"` \
	-p $SOCKET
    RETVAL=$?
    if [ $RETVAL = 0 ] ; then
	echo "[  OK  ]"
    else
	echo "[FAILED]"
	kill `cat $MXPID`
	return 1
    fi
    return 0
}

stop_it() {
    # Stop daemon
    printf "%-60s" "Shutting down $prog: "
    if test -f "$PID" ; then
	kill `cat $PID`
	RETVAL=$?
	# killing the parent does not work when the children are still
	# running
	killall $PROGDIR/$prog
    else
	RETVAL=1
    fi
    if [ $RETVAL = 0 ] ; then
	echo "[  OK  ]"
    else
	echo "[FAILED]"
    fi

    # Stop daemon
    printf "%-60s" "Shutting down $prog-multiplexor: "
    if test -f "$MXPID" ; then
	kill `cat $MXPID`
	RETVAL=$?
    else
	RETVAL=1
    fi
    if [ $RETVAL = 0 ] ; then
	echo "[  OK  ]"
    else
	echo "[FAILED]"
    fi

    rm -f $MX_SOCKET > /dev/null 2>&1
    rm -f $SOCKET > /dev/null 2>&1

    if [ "$1" = "wait" ] ; then
	printf "Waiting for daemons to exit."
	WAITPID=""
	test -f $PID && WAITPID=`cat $PID`
	test -f $MXPID && WAITPID="$WAITPID `cat $MXPID`"
	n=0
	while [ -n "$WAITPID" ] ; do
	    W2=""
	    for pid in $WAITPID ; do
		if kill -0 $pid > /dev/null 2>&1 ; then
		    W2="$W2 $pid"
		fi
	    done
	    printf "."
	    n=`expr $n + 1`
	    test $n -eq 30 && kill -KILL $WAITPID > /dev/null 2>&1
	    test $n -eq 60 && break
	    WAITPID=$W2
	    sleep 1
	done
	echo ""
    fi

    rm -f $MXPID > /dev/null 2>&1
    rm -f $PID > /dev/null 2>&1
}

# See how we were called.
case "$1" in
  start)
  start_it
    ;;

  stop)
  stop_it $2
    ;;

  restart|force-reload)
    stop_it wait
    start_it
    RETVAL=$?
    ;;

  reread|reload)
	if [ -x $PROGDIR/md-mx-ctrl ] ; then
	    $PROGDIR/md-mx-ctrl -s $MX_SOCKET reread > /dev/null 2>&1
	    RETVAL=$?
	    if [ $RETVAL = 0 ] ; then
		echo "Told $prog-multiplexor to force reread of filter rules."
	    else
		echo "Could not communicate with $prog-multiplexor"
	    fi
	else
	    if [ -r $MXPID ] ; then
		kill -INT `cat $MXPID`
		RETVAL=$?
		if [ $RETVAL = 0 ] ; then
		    echo "Told $prog-multiplexor to force reread of filter rules."
		else
		    echo "Could not signal $prog-multiplexor"
		fi
	    else
		RETVAL=1
		echo "Could not find process-ID of $prog-multiplexor"
	    fi
	fi
    ;;

  *)
    echo "Usage: $0 {start|stop|restart|force-reload|reread|reload}"
    exit 1
esac

exit $RETVAL