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
|
#! /bin/sh
# This file is part of mailfromd.
# Copyright (C) 2005, 2006, 2007 Sergey Poznyakoff
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PIDFILE=<DEFAULT_PIDFILE>
DAEMON=<DEFAULT_DAEMON>
ARGS=""
PS="ps axwwww"
mailfromd_start() {
if mailfromd_status -q; then
cat >&2 <<-EOT
Mailfromd seems to be running.
Try \`$0 status' to examine, or \`$0 restart' to force restart.
EOT
exit 1
fi
echo "Starting mailfromd..."
rm -f $PIDFILE
if eval $DAEMON $ARGS ; then
if [ ! -r $PIDFILE ]; then
sleep 1
test -r $PIDFILE || echo "mailfromd NOT started" >&2
fi
else
echo "mailfromd failed to start" >&2
fi
}
mailfromd_stop() {
echo "Stopping mailfromd..."
if [ -r $PIDFILE ]; then
PID=`head -n 1 $PIDFILE`
kill -TERM -$PID 2>/dev/null
N=0
while [ -r $PIDFILE ]
do
N=$(($N + 1))
if [ $N -gt 5 ]; then
break
fi
sleep 1
done
if [ -r $PIDFILE ]; then
echo "Still running. Killing it..." >&2
kill -KILL $PID 2>/dev/null
rm $PIDFILE
fi
else
echo "mailfromd is not running" >&2
fi
}
mailfromd_status() {
if [ -r $PIDFILE ]; then
PID=`head -n 1 $PIDFILE`
if [ "$1" != "-q" ]; then
echo "mailformd appears to be running at $PID"
fi
else
PID='[0-9][0-9]*'
fi
$PS | grep "[0-9]:[0-9][0-9] $DAEMON" |
while read pid tt stat time command
do
echo $pid $command
done |
grep $1 "$PID $DAEMON"
}
mailfromd_reload() {
echo "Reloading mailfromd..."
if mailfromd_status -q; then
PID=`head -n 1 $PIDFILE`
kill -HUP $PID 2>/dev/null
if [ ! -r $PIDFILE ]; then
sleep 1
test -r $PIDFILE || echo "mailfromd failed to reload" >&2
fi
else
echo "mailfromd is not running"
fi
}
mailfromd_configtest() {
case $# in
0) CFGOPT=;;
1) CFGOPT=$1;;
*) echo "$0: too many arguments, try \`$0 help' for more info" >&2
exit 1;;
esac
$DAEMON $CFGOPT --lint
}
export_cf_macros() {
echo "O Milter.macros.$1=$2"
}
export_mc_macros() {
un=`echo $1 | tr a-z A-Z`
echo "define(\`confMILTER_MACROS_$un', ifdef(\`confMILTER_MACROS_$un',\`confMILTER_MACROS_$un\`,' ')\`$2')"
}
mailfromd_macros() {
EXPORT=export_mc_macros
CFGOPT=
while [ $# -ne 0 ]
do
case $1 in
-c|--cf) EXPORT=export_cf_macros; shift;;
--) shift; break;;
-*) echo "$0: unknown command line option: $1" >&2; exit 1;;
*) if [ $# -eq 1 ]; then
if [ -r $1 ]; then
CFGOPT="$1"
else
echo "$0: \`$1' does not exist or is unreadable" >&2
exit 1
fi
break
else
echo "$0: too many arguments, try \`$0 help' for more info" >&2
exit 1
fi;;
esac
done
IOUTPUT=
$DAEMON $CFGOPT --dump-macros |
while read state rest
do
if [ -z "$IOTPUT" ]; then
if [ "$state" != "helo" ]; then
$EXPORT helo i
else
rest="i, $rest"
fi
IOTPUT=yes
fi
$EXPORT $state "$rest"
done
exit 0
}
case $1 in
start) mailfromd_start;;
stop) mailfromd_stop;;
reload)
mailfromd_reload;;
restart)
mailfromd_stop
sleep 1
mailfromd_start;;
status)
mailfromd_status;;
configtest)
shift
mailfromd_configtest $@;;
macros)
shift
mailfromd_macros $@;;
help) cat <<EOT
usage: $0 COMMAND [OPTIONS]
COMMANDS are:
start Start the daemon.
stop Stop the running instance of the daemon.
reload Reload the daemon by sending SIGHUP to its running copy.
restart Restart the daemon.
status Display status of the running instance.
configtest [FILE] Check configuration file syntax. If FILE is not
given, the default one is assumed.
macros [OPTIONS] [FILE]
Generate milter export statements for Sendmail
configuration files. Optional FILE specifies
alternative mailfromd configuration file.
OPTIONS are:
-c, --cf Generate output, suitable for sendmail.cf
file (by default, \`.mc' format is assumed).
EOT
;;
*) echo "Usage: $0 {start|stop|reload|restart|status|configtest|macros}" >&2
echo "Try \`$0 help' for more info" >&2
esac
# End of rc.mailfromd
|