1MIMEDEFANG-MULTIPLEXOR(8)   System Manager's Manual  MIMEDEFANG-MULTIPLEXOR(8)
2
3
4

NAME

6       mimedefang-multiplexor - Process pool controller for mail filters.
7

SYNOPSIS

9       mimedefang-multiplexor [options]
10
11

DESCRIPTION

13       mimedefang-multiplexor manages a pool of Perl processes for scanning e-
14       mail.  It is designed to work in  conjunction  with  mimedefang(8)  and
15       mimedefang.pl(8).
16
17       mimedefang-multiplexor  opens  a  UNIX-domain  socket  and  listens for
18       requests for work from mimedefang.  As requests  come  in,  mimedefang-
19       multiplexor  creates  Perl  processes as needed to scan mail.  The Perl
20       processes are not killed when scanning is completed,  but  continue  to
21       run  in  a loop.  Perl processes are re-used for subsequent e-mail mes‐
22       sages.  This eliminates the large  overhead  of  starting  a  new  Perl
23       process for each incoming message.
24
25       To  avoid  memory  leaks, the Perl processes are killed after they have
26       handled some number of scans.
27
28

OPTIONS

30       -U user
31              Runs the multiplexor as user rather than root.  This  option  is
32              mandatory, and must match the -U option supplied to mimedefang.
33
34
35       -m minWorkers
36              The  minimum  number  of  Perl  processes to keep running at all
37              times.  The default is zero.
38
39
40       -x maxWorkers
41              The maximum number of Perl processes to run simultaneously.   If
42              a request comes in and all processes are busy, a temporary fail‐
43              ure is signalled to the SMTP peer.  The default is 2.
44
45
46       -r maxRequests
47              The maximum number of requests a given process handles before it
48              is killed and a replacement started.  The default is 500.
49
50
51       -i idleTime
52              The idle time in seconds after which to kill of excess Perl pro‐
53              cesses.  That is, if the process is idle for  longer  than  this
54              time, and there are more than minWorkers running, the process is
55              killed.  Note that this is implemented as a  timer  which  ticks
56              every  idleTime seconds; therefore, processes may be idle for up
57              to twice this time before they  are  killed.   The  default  for
58              idleTime is 300 seconds.
59
60
61       -V maxLifetime
62              The  maximum lifetime in seconds of a worker before it is killed
63              and a replacement started.  The default is -1,  which  signifies
64              no  maximum lifetime.  Note that the lifetime check is done only
65              when a worker becomes idle after a request, or  every  time  the
66              idle-timeout check is made.  On a very quiet system, workers may
67              live for longer than maxLifetime by as much as  idleTime.   Note
68              also  that  the  lifetime  is  measured not from when the worker
69              started running, but from when it was assigned  its  very  first
70              request.   A completely-idle worker that has never processed any
71              requests will not be terminated by the maxLifetime setting.
72
73
74       -b busyTime
75              The longest a Perl process is allowed to spend  scanning  an  e-
76              mail  before  it is declared hung up and killed.  The default is
77              120 seconds.
78
79
80       -Z     This option specifies that the  multiplexor  should  accept  and
81              process "status updates" from busy workers.  Note that this con‐
82              sumes one extra file descriptor per worker, plus a small  amount
83              of CPU time per status update.
84
85
86       -c cmdTime
87              The timeout for communication between mimedefang-multiplexor and
88              mimedefang, or between mimedefang-multiplexor and a  Perl  scan‐
89              ning  process.   The default is 10 seconds.  This timeout should
90              be kept quite short.
91
92
93       -w waitTime
94              When mimedefang-multiplexor starts the initial workers, or needs
95              to  bring the number of running workers up to the number defined
96              by the -m option, it does not start all  the  workers  at  once,
97              because this could overload your server.  Instead, it starts one
98              worker every waitTime seconds.  The default value  for  waitTime
99              is 3.
100
101
102       -W waitTime
103              If  you use this option, mimedefang-multiplexor will never acti‐
104              vate a worker until waitTime seconds have elapsed since the last
105              worker  activation.   This could result in mail being tempfailed
106              if worker activations do not keep pace with incoming mail.  How‐
107              ever,  it  may  be preferable to tempfail mail rather than allow
108              the load on your server to spike up too  quickly.   The  default
109              value  for this option is 0, meaning that mimedefang-multiplexor
110              will start workers as quickly  as  necessary  to  keep  up  with
111              incoming mail.
112
113
114       -z spooldir
115              Set the spool directory to spooldir.  If this option is omitted,
116              the spool directory defaults to /var/spool/MIMEDefang.
117
118
119       -s pathName
120              The UNIX-domain socket on which  mimedefang-multiplexor  listens
121              for requests.  This should be specified as an absolute pathname.
122              If this option is not supplied, it defaults to mimedefang-multi‐
123              plexor.sock under the spool directory.
124
125
126       -a socket
127              A  socket for listening for requests.  This is similar to the -s
128              socket, except that a restricted set of requests are  processed.
129              On  this socket, the multiplexor will only process requests ask‐
130              ing for status; it will not accept any commands to  do  scanning
131              or  that  would  consume a worker.  See the SOCKET SPECIFICATION
132              section for the format of socket.
133
134
135       -p fileName
136              Causes mimedefang-multiplexor to  write  its  process-ID  (after
137              becoming  a  daemon)  to  the  specified file.  The file will be
138              owned by root.
139
140
141       -o fileName
142              Causes mimedefang-multiplexor to use fileName as a lock file  to
143              avoid multiple instances from running.  If you supply -p but not
144              -o,  then  mimedefang-multiplexor  constructs  a  lock  file  by
145              appending ".lock" to the pid file.  However, this is less secure
146              than having a root-owned pid file in a root-owned directory  and
147              a  lock  file writable by the user named by the -U option.  (The
148              lock file must be writable by the -U user.)
149
150
151       -f filter_path
152              Normally, mimedefang-multiplexor executes a Perl  filter  script
153              called  mimedefang.pl to scan the e-mail.  However, you can have
154              it execute any program you like by specifying the full  path  to
155              the program with the -f option.  This program must obey the pro‐
156              tocol documented in mimedefang-protocol(7); see that manual page
157              for details.
158
159              Note  that  the  -f  option does not specify the "filter" to use
160              with  mimedefang.pl;  instead,  it  specifies  the  program  for
161              mimedefang-multiplexor  to execute.  You almost certainly should
162              not use this option unless you  wish  to  replace  mimedefang.pl
163              with your own program.
164
165
166       -F rules_path
167              Specifies   the   path   to   the  filter  rules.   By  default,
168              /etc/mail/mimedefang-filter is used.  If you use the -F  option,
169              its  value is passed to the underlying Perl filter program using
170              -f.
171
172
173       -l     Log certain events, including the output of  the  Perl  workers'
174              standard-error,  using  syslog.   Normally, the multiplexor does
175              not log much information.
176
177
178       -d     Write  debugging  information  about  event-handling   code   in
179              /var/log/mimedefang-event-debug.log.   This  is  only  of use to
180              people debugging mimedefang-multiplexor.
181
182
183       -R kbytes
184              Limits the resident-set size of the worker filter  processes  to
185              kbytes  kilobytes.  This limit is not supported on all operating
186              systems; it is known to work on Linux.
187
188
189       -M kbytes
190              Limits the total memory space  of  worker  filter  processes  to
191              kbytes kilobytes.  This limit is supported on all operating sys‐
192              tems which support the setrlimit(2) system  call.   This  should
193              include most modern UNIX systems.
194
195              We  recommend  that you monitor your worker filter processes and
196              get a feel for how much memory they use.  You should then  limit
197              the  memory  to  two or three times the worst-case that you have
198              observed.  This  can  help  mitigate  denial-of-service  attacks
199              which  use  complicated  MIME messages to force mimedefang.pl to
200              consume lots of memory.
201
202
203       -h     Print usage information and exit.
204
205
206       -t filename
207              Log statistical information to filename.  See the  section  STA‐
208              TISTICS for more information.
209
210
211       -T     Log statistical information using syslog(2).  You may use any -t
212              and -T together, in which case statistical information is logged
213              in a file and using syslog.
214
215
216       -u     Flush  the statistics file after every write.  Normally, mimede‐
217              fang-multiplexor does not flush  the  file;  this  is  the  best
218              choice  for minimizing disk I/O on a busy mail server.  However,
219              if you wish to watch statistics entries in real-time, you should
220              enable flushing.
221
222
223       -D     Do  not  fork into the background and become a daemon.  Instead,
224              stay in the foreground.  Useful mainly for debugging or  if  you
225              have a supervisory process managing mimedefang-multiplexor.
226
227
228       -q queue_size
229              Normally,  if  all  workers  are busy and mimedefang-multiplexor
230              receives another request, it fails it with the  error  "No  free
231              workers."   However,  if  you  use  the  -q  option,  then up to
232              queue_size requests will be queued.  As soon as a worker becomes
233              free,  the queued requests will be handed off in FIFO order.  If
234              the queue is full and another request comes in, then the request
235              is failed with "No free workers".
236
237
238       -Q queue_timeout
239              Queued requests should not stay on the queue indefinitely.  If a
240              queued request cannot be processed within queue_timeout (default
241              30)  seconds  of  being placed on the queue, it is failed with a
242              "Queued request timed out" message.  See the  section  "QUEUEING
243              REQUESTS" for more discussion.
244
245
246       -O sock
247              Listen  on a notification socket for connections from listeners.
248              mimedefang-multiplexor can inform  external  programs  of  state
249              changes  by  sending  messages  over a notification socket.  The
250              external programs connect to this socket  and  then  listen  for
251              notifications.   See  the  section  SOCKET SPECIFICATION for the
252              format of sock.
253
254              See the mimedefang-notify(7) man page for details of the notifi‐
255              cation protocol.
256
257
258       -N map_sock
259              Listen  on  a map socket for Sendmail SOCKETMAP connections.  As
260              of Sendmail 8.13, you can define a Sendmail map type that  talks
261              to  a  daemon  over a socket.  mimedefang-multiplexor implements
262              that protocol; consult the  mimedefang-filter(5)  man  page  for
263              detils (see the SOCKET MAPS section).
264
265              See the section SOCKET SPECIFICATION for the format of map_sock.
266
267
268
269
270       -I backlog
271              When  mimedefang-multiplexor creates a listening socket, it cal‐
272              culates the "backlog" argument to listen(2) based on the maximum
273              number of workers.  However, you can explicitly set this backlog
274              with the -I option.  Setting the backlog to a high value (around
275              30-50) may help on a very busy server.  If you see mail log mes‐
276              sages saying "MXCommand: socket: Connection refused" during busy
277              periods,  then  that's  an  indication  you need a higher listen
278              backlog.
279
280
281       -L interval
282              Log the worker status every interval seconds.  This logs a  line
283              using syslog; the line looks like this:
284
285
286       Worker status: Stopped=s Idle=i Busy=b Killed=k Queued=q Msgs=m Activations=a
287
288              Here,  "Stopped" is the number of non-running workers, "Idle" is
289              the number of idle workers, "Busy" is the number of  busy  work‐
290              ers,  "Killed" is the number of killed workers yet to be reaped,
291              "Queued" is the number of queued requests, "Msgs" is  the  total
292              number  of  messages  processed since the multiplexor began run‐
293              ning, and "Activations" is the number of times  a  Perl  process
294              has been started since the multiplexor began running.
295
296              If  you supply an interval of 0 (which is the default), no peri‐
297              odic status logging is performed.  If you supply an interval  of
298              less than 5 seconds, it is silently reset to 5 seconds.
299
300
301       -S facility
302              Specifies  the syslog facility for log messages.  The default is
303              mail.  See openlog(3) for a list of valid facilities.   You  can
304              use either the short name ("mail") or long name ("LOG_MAIL") for
305              the facility name.
306
307
308       -E     Specifies that the multiplexor should create  an  embedded  Perl
309              interpreter.   This  can  improve performance dramatically.  But
310              see the section "EMBEDDING PERL" for more information.
311
312
313       -X n   Specifies that the multiplexor should initiate a "tick"  request
314              every  n  seconds.   This  causes  your filter_tick function (if
315              defined) to be called.  Note that you have no control over which
316              worker  executes  filter_tick.   If  all workers are busy when a
317              tick occurs, that tick request is skipped and a warning  message
318              is logged.
319
320
321       -P n   Specifies  that  the  multiplexor  should run n tick requests in
322              parallel.  Each tick is run as often as specified  with  the  -X
323              argument.   (If  you  omit  the  -P option, then the multiplexor
324              behaves as if -P 1 had been specified.)
325
326              If you run parallel ticks, each  tick  is  assigned  an  integer
327              identifying  its  "type".  The type ranges from 0 to n-1.  While
328              there may be as many as n tick requests running at a time,  only
329              one tick of each type will be active at any time.
330
331
332       -Y label
333              Sets  the tag used in the multiplexor's syslog messages to label
334              instead of mimedefang-multiplexor.
335
336
337       -G     Normally, mimedefang-multiplexor uses a umask of 027 when creat‐
338              ing  listening  sockets.   If  you  would like the sockets to be
339              readable and writeable by the group as well as the owner, supply
340              the  -G  option.  This causes the umask to be 007 whenever UNIX-
341              domain sockets are created.
342
343
344       -y n   Limits the maximum number of concurrent recipok checks to n on a
345              per-domain  basis.   The  value  of n can range from 0 (in which
346              case no limit is applied) to maxWorkers, where maxWorkers is the
347              argument  to  the  -x option.  If n is outside that range, it is
348              ignored (and no limit is applied.)
349
350
351              The recipok  command  ultimately  invokes  the  filter_recipient
352              function  in  your filter.  If you are doing recipient verifica‐
353              tion against servers that may be slow or unreliable, you can use
354              the  -y option to limit the number of concurrent recipient veri‐
355              fications per domain.  That way, if one domain's server  becomes
356              very  slow, it won't consume all available workers for recipient
357              verification.  Instead, its RCPT commands will be tempfailed and
358              there  will  be  workers  available  to handle RCPT commands for
359              other domains.
360
361

SOCKET SPECIFICATION

363       The -a, -N and -O options take a socket as an  argument.   This  socket
364       can be specified as:
365
366
367       /path/to/socket
368              A UNIX-domain socket
369
370
371       inet:portnum
372              A  TCP  socket  bound to port portnum, but which accepts connec‐
373              tions only from the IPv4 loopback address (127.0.0.1).
374
375
376       inet_any:portnum
377              A TCP socket bound to port portnum which will accept connections
378              from any address.  Use inet_any with caution!
379
380
381       inet6:portnum
382              A  TCP  socket bound to port portnum listening on the IPv6 loop‐
383              back address.
384
385
386       inet6_any:portnum
387              A TCP socket bound to port portnum listening on the  IPv6  wild‐
388              card address.
389
390

QUEUEING REQUESTS

392       Normally,  if  all workers are busy, any additional requests are failed
393       immediately.  However, the  -q  and  -Q  options  allow  you  to  queue
394       requests  for  a  short  amount  of time.  This facility is intended to
395       gracefully handle a temporary overload; most of the  time,  your  queue
396       should be empty.
397
398       Because  mimedefang checks the number of free workers when a connection
399       is opened and fails the connection if there are no  free  workers,  the
400       intent  of  the  queue  is  to allow SMTP transactions that are already
401       underway to continue if there is a slight overload.   Any  new  connec‐
402       tions  will be failed if all workers are busy, but existing connections
403       are allowed to continue.  Queuing requests may  improve  throughput  on
404       extremely busy servers.
405
406       Note that if you supply the -q option to mimedefang, then even new con‐
407       nections are allowed to queue.  This may improve throughput by  keeping
408       the worker utilization higher.
409
410       The  -R  option to mimedefang can be used to reserve a specified number
411       of workers for connections from the loopback  address.   Using  the  -R
412       option has the side-effect of permitting new connections from the loop‐
413       back address to queue.
414
415

EMBEDDING PERL

417       Normally, when mimedefang-multiplexor activates a worker, it forks  and
418       execs  mimedefang.pl.   However,  if  the multiplexor was compiled with
419       embedded Perl support, and you supply the -E command-line  option,  the
420       multiplexor works like this:
421
422
423       1      It  creates  an  embedded  Perl interpreter, and sources mimede‐
424              fang.pl with a special command-line argument telling it to  read
425              the filter, but not to enter the main loop.
426
427
428       2      Each  time  a  worker is activated, the multiplexor calls fork()
429              and runs the mimedefang.pl main loop.  This invokes  filter_ini‐
430              tialize and then runs the main loop.
431
432
433       On  some platforms (for example, Red Hat Linux 7.3 with Perl 5.6.1), it
434       is not safe to destroy and recreate a Perl interpreter without  causing
435       a memory leak.  On those platforms, if you attempt to reread the filter
436       file (by sending the multiplexor a HUP signal or reread  command),  the
437       filter will not be re-read, and a message will be logged to syslog.  On
438       those platforms, you must kill and restart MIMEDefang if you change the
439       filter file.
440
441
442       On most platforms, however, a filter reread is accomplished by destroy‐
443       ing and re-creating the embedded interpreter, re-sourcing mimedefang.pl
444       and killing workers as soon as they are idle.
445
446

STATISTICS

448       With  the  -t  option,  mimedefang-multiplexor logs certain events to a
449       file.  This file can be post-processed to gather statistics  about  the
450       multiplexor.   You  can  use  it to tune the number of workers you run,
451       adjust timeouts, and so on.
452
453
454       Each line of the file looks like this:
455
456            YYYY/MM/DD:HH:MM:SS timestamp event key=val key=val...
457
458       Here, YYYY/MM/DD:HH:MM:SS is the local time of day.  Timestamp  is  the
459       number  of  seconds  since  January  1,  1970.  Event is the name of an
460       event.  The valid events are:
461
462
463       StartWorker
464              A worker process has been started.
465
466
467       KillWorker
468              A worker process has been killed.
469
470
471       ReapWorker
472              A dead worker process has been reaped.  It is possible to have a
473              ReapWorker  event  without  a  previous  KillWorker event if the
474              worker process terminated abnormally.
475
476
477       StartFilter
478              A worker process has begun filtering an e-mail message.
479
480
481       EndFilter
482              A worker process has finished filtering an e-mail message.
483
484
485       The possible keys in the key=value pairs are:
486
487
488       worker=n
489              The worker involved in the event.  Every worker is identified by
490              a small integer.
491
492
493       nworkers=n
494              The  total number of running workers immediately after the event
495              happened.
496
497
498       nbusy=n
499              The number of busy workers (workers which are processing  an  e-
500              mail message) immediately after the event happened.
501
502
503       reason="string"
504              The reason for a StartWorker or KillWorker event.  (Present only
505              for these events.)
506
507
508       numRequests=n
509              The number of e-mails processed by the worker.  Present only for
510              an EndFilter event.
511
512
513       If you send the mimedefang-multiplexor process a SIGHUP signal (kill -1
514       pid), it closes and reopens the statistics file.  This is useful during
515       log file rotation.
516
517
518       If  you  send  the mimedefang-multiplexor process a SIGINT signal (kill
519       -INT pid),  it  terminates  all  active-but-idle  workers.   Also,  any
520       active-and-busy  workers terminate as soon as they finish filtering the
521       current message.  This is useful to force a reread of the filter  rules
522       file without stopping and restarting Sendmail.
523
524
525       If  you  send the mimedefang-multiplexor process a SIGTERM signal (kill
526       pid), it terminates all workers and exits immediately.
527
528

AUTHOR

530       mimedefang-mulitplexor was written  by  Dianne  Skoll  <dfs@roaringpen‐
531       guin.com>.  The mimedefang home page is http://www.mimedefang.org/.
532
533

SEE ALSO

535       mimedefang.pl(8),  mimedefang-filter(5), mimedefang(8), mimedefang-pro‐
536       tocol(7)
537
538
539
540
541
5424th Berkeley Distribution       8 February 2005      MIMEDEFANG-MULTIPLEXOR(8)
Impressum