]> Pileus Git - ~andy/sunrise/blob - mail-filter/MailScanner/files/initd.mailscanner-mta
dev-perl/Filesys-Df: CL tweak
[~andy/sunrise] / mail-filter / MailScanner / files / initd.mailscanner-mta
1 #!/sbin/runscript
2 # Tis init script takes care of starting the MTA processes for use 
3 # with MailScanner.
4
5 opts="${opts} status reload startin startout stopin stopout restartin restartout"
6
7 checkmta() {
8         ebegin "checking MTA availability for MailScanner"
9         if [ ${MTA} = 'sendmail' ]; then
10                 if [ -f ${SENDMAIL} ]; then
11                         eend 0
12                         return
13                 else
14                         echo "Cannot find sendmail, check /etc/conf.d/MailScanner-mta"
15                         eend 1
16                         exit
17                 fi
18         elif [ ${MTA} = "postfix" ]; then
19                 if test -x ${POSTFIX} -a -f ${POSTFIXINCF}/main.cf \
20                    -a -f ${POSTFIXOUTCF}/main.cf ; then
21                         eend 0
22                         return
23                 else
24                         echo "Cannot find postfix and/or postfix configuration files,"
25                         echo "Check /etc/conf.d/MailScanner-mta"
26                         eend 1
27                         exit
28                 fi
29         elif [ ${MTA} = "exim" ]; then
30                 if test -x ${EXIM} -a -f ${EXIMINCF} -a -f ${EXIMSENDCF}; then
31                         eend 0
32                         return
33                 else
34                         echo "Cannot find exim and/or exim configuration files,"
35                         echo "Check /etc/conf.d/MailScanner-mta"
36                         eend 1
37                         exit
38                 fi
39         else
40                 echo "Invalid MTA in /etc/conf.d/MailScanner-mta"
41                 eend 1
42                 exit
43         fi
44 }
45 aliasesetc() {
46         /usr/bin/newaliases > /dev/null 2>&1
47         retval=$?
48         if test -x /usr/bin/make -a -f /etc/mail/Makefile ; then
49                 make -C /etc/mail -s
50                 let retval+=$?
51         else
52                 for i in virtusertable access domaintable mailertable ; do
53                         if [ -f /etc/mail/$i ] ; then
54                                 makemap hash /etc/mail/$i < /etc/mail/$i
55                                 let retval+=$?
56                         fi
57                 done
58         fi
59         return ${retval}
60 }
61
62 startinreal () {
63         if [ ${MTA} = "sendmail" ]; then
64                 ( cd /var/spool/mqueue.in; rm -f xf*)
65                 aliasesetc
66                 ${SENDMAIL} -bd -OPrivacyOptions=noetrn \
67                                                 -ODeliveryMode=queueonly \
68                                                 -OQueueDirectory=${INQDIR} \
69                                                 -OPidFile=${INPID}
70                 retval=$?
71                 touch ${SMPID}
72                 chown ${MSPUSER}:${MSPGROUP} ${SMPID} 2> /dev/null
73                 ${SENDMAIL} -L sm-msp-queue -Ac -q15m -OPidFile=${SMPID} 2> /dev/null
74                 let retval+=$?
75                 return ${retval}
76         elif [ ${MTA} = "postfix" ]; then
77                 ${POSTFIX} -c ${POSTFIXINCF} start 2> /dev/null
78                 return $?
79         elif [ ${MTA} = "exim" ]; then
80                 ${EXIM} -c ${EXIMINCF} start 2> /dev/null
81                 return $?
82         fi
83 }
84
85 startoutreal() {
86         if [ ${MTA} = "sendmail" ]; then
87                 ${SENDMAIL} $([ -n "${QUEUETIME}" ] && echo -q${QUEUETIME}) \
88                                 -OPidFile=${OUTPID}
89                 return $?
90         elif [ ${MTA} = "postfix" ]; then
91                 ${POSTFIX} -c ${POSTFIXOUTCF} start 2> /dev/null
92                 return $?
93         elif [ ${MTA} = "exim" ]; then
94                 ${EXIM} -c ${EXIMSENDCF} -q15m 2> /dev/null
95                 return $?
96         fi
97 }
98
99 stopinreal() {
100         if [ ${MTA} = "sendmail" ]; then
101                 kill ${KILL_OPTS} `head -n 1 ${INPID}` 2> /dev/null
102                 retval=$?
103                 kill ${KILL_OPTS} `head -n 1 ${SMPID}` 2> /dev/null
104                 let retval+=$?
105                 return ${retval}
106         elif [ ${MTA} = "postfix" ]; then
107                 ${POSTFIX} -c ${POSTFIXINCF} stop 2> /dev/null
108                 return $?
109         fi
110 }
111
112 stopoutreal() {
113         if [ ${MTA} = "sendmail" ]; then
114                 kill ${KILL_OPTS} `head -n 1 ${OUTPID}` 2> /dev/null
115                 return $?
116         elif [ ${MTA} = "postfix" ]; then
117                 ${POSTFIX} -c ${POSTFIXOUTCF} stop 2> /dev/null
118                 return $?
119         fi
120 }
121
122
123
124
125 depend() {
126         need net
127         use logger dns
128         provide mta
129 }
130
131 start() {
132         checkmta
133         ebegin "Starting incoming ${MTA}"
134         startinreal
135         retval=$?
136         eend ${retval}
137         if [ ${retval} -gt 0 ]; then
138                 exit
139         fi
140         ebegin "Starting outgoing ${MTA}"
141         startoutreal
142         retval=$?
143         eend ${retval}
144         if [ ${retval} -gt 0 ]; then
145                 echo "Will attempt to stop incoming ${MTA}"
146                 stopinreal
147         fi
148 }
149
150 stop() {
151         checkmta
152         if [ ${MTA} = "exim" ]; then
153                 ebegin "Stopping exim"
154                 killall ${KILL_OPTS} exim
155                 eend $?
156         else
157                 ebegin "Stopping incoming ${MTA}"
158                 stopinreal
159                 eend $?
160                 ebegin "Stopping outgoing ${MTA}"
161                 stopoutreal
162                 eend $?
163         fi
164 }
165
166 startin() {
167         checkmta
168         ebegin "Starting incoming ${MTA}"
169         startinreal
170         eend $?
171 }
172
173 startout() {
174         checkmta
175         ebegin "Starting outgoing ${MTA}"
176         startoutreal
177         eend $?
178 }
179
180 stopin() {
181         checkmta
182         if [ ${MTA} = "exim" ]; then
183                 ebegin "Stopping incoming exim"
184                 echo "It is not possible to stop only the incoming exim.";
185                 echo "Please use the stop option, then use startin or startout to restart"
186                 echo "the incoming or outgoing process."
187                 eend 1
188         else
189                 ebegin "Stopping incoming ${MTA}"
190                 stopinreal
191                 eend $?
192         fi
193 }
194
195 stopout() {
196         checkmta
197         if [ ${MTA} = "exim" ]; then
198                 ebegin "Stopping outgoing exim"
199                 echo "It is not possible to stop only the outgoing exim.";
200                 echo "Please use the stop option, then use startin or startout to restart"
201                 echo "the incoming or outgoing process."
202                 eend 1
203         else
204                 ebegin "Stopping outgoing ${MTA}"
205                 stopoutreal
206                 eend $?
207         fi
208 }
209
210 restartin() {
211         stopin
212         startin
213 }
214
215 restartout() {
216         stopout
217         startout
218 }
219
220 status() {
221         if [ ${MTA} = 'sendmail' ]; then
222                 ebegin "Incoming Sendmail status"
223                 pid=`head -n 1 ${INPID}`
224                 alive=`ps ax | awk '{ print $1 }' | grep '^'$pid'$'`
225                 if [ -z "${alive}" ]; then eend 1; else eend 0; fi
226                 ebegin "Client submission Sendmail status"
227                 pid=`head -n 1 ${SMPID}`
228                 alive=`ps ax | awk '{ print $1 }' | grep '^'$pid'$'`
229                 if [ -z "${alive}" ]; then eend 1; else eend 0; fi
230                 ebegin "Outgoing Sendmail status"
231                 pid=`head -n 1 ${OUTPID}`
232                 alive=`ps ax | awk '{ print $1 }' | grep '^'$pid'$'`
233                 if [ -z "${alive}" ]; then eend 1; else eend 0; fi
234         elif [ ${MTA} = 'postfix' ]; then
235                 echo "Sorry: status is not supported for postfix"
236         elif [ ${MTA} = 'exim' ]; then
237                 echo "Sorry: status is not supported for exim"
238         else 
239                 echo "Invalid MTA in /etc/conf.d/MailScanner-mta"
240                 exit
241         fi
242
243 }
244
245 reload() {
246         if [ ${MTA} = 'sendmail' ]; then
247                 ebegin "Reloading Sendmail configuration"
248                 aliasesetc
249                 eend $?
250         elif [ ${MTA} = 'postfix' ]; then
251                 ebegin "Reloading Incoming Postfix"
252                 ${POSTFIX} -c ${POSTFIXINCF} reload > /dev/null
253                 eend $?
254                 ebegin "Reloading Outgoing Postfix"
255                 ${POSTFIX} -c ${POSTFIXOUTCF} reload > /dev/null
256                 eend $?
257         elif [ ${MTA} = 'exim' ]; then
258                 echo "Sorry: reload is not supported for exim"
259         else 
260                 echo "Invalid MTA in /etc/conf.d/MailScanner-mta"
261                 exit
262         fi
263 }