op.me

来自「< linux网络编程工具>>配套源码」· ME 代码 · 共 2,453 行 · 第 1/5 页

ME
2,453
字号
.sm LOG_DEBUG
priority.
.sh 2 "The Mail Queue"
.pp
Sometimes a host cannot handle a message immediately.
For example, it may be down or overloaded, causing it to refuse connections.
The sending host is then expected to save this message in
its mail queue
and attempt to deliver it later.
.pp
Under normal conditions the mail queue will be processed transparently.
However, you may find that manual intervention is sometimes necessary.
For example,
if a major host is down for a period of time
the queue may become clogged.
Although
.i sendmail
ought to recover gracefully when the host comes up,
you may find performance unacceptably bad in the meantime.
.sh 3 "Printing the queue"
.pp
The contents of the queue can be printed
using the
.i mailq
command
(or by specifying the
.b \-bp
flag to
.i sendmail ):
.(b
mailq
.)b
This will produce a listing of the queue id's,
the size of the message,
the date the message entered the queue,
and the sender and recipients.
.sh 3 "Forcing the queue"
.pp
.i Sendmail
should run the queue automatically
at intervals.
When using multiple queues,
a separate process will be created to
run each of the queues
unless the queue run is initiated by a user
with the verbose flag.
The algorithm is to read and sort the queue,
and then to attempt to process all jobs in order.
When it attempts to run the job,
.i sendmail
first checks to see if the job is locked.
If so, it ignores the job.
.pp
There is no attempt to insure that only one queue processor
exists at any time,
since there is no guarantee that a job cannot take forever
to process
(however,
.i sendmail
does include heuristics to try to abort jobs
that are taking absurd amounts of time;
technically, this violates RFC 821, but is blessed by RFC 1123).
Due to the locking algorithm,
it is impossible for one job to freeze the entire queue.
However,
an uncooperative recipient host
or a program recipient
that never returns
can accumulate many processes in your system.
Unfortunately,
there is no completely general way to solve this.
.pp
In some cases,
you may find that a major host going down
for a couple of days
may create a prohibitively large queue.
This will result in
.i sendmail
spending an inordinate amount of time
sorting the queue.
This situation can be fixed by moving the queue to a temporary place
and creating a new queue.
The old queue can be run later when the offending host returns to service.
.pp
To do this,
it is acceptable to move the entire queue directory:
.(b
cd /var/spool
mv mqueue omqueue; mkdir mqueue; chmod 700 mqueue
.)b
You should then kill the existing daemon
(since it will still be processing in the old queue directory)
and create a new daemon.
.pp
To run the old mail queue,
run the following command:
.(b
/usr/\*(SD/sendmail \-oQ/var/spool/omqueue \-q
.)b
The
.b \-oQ
flag specifies an alternate queue directory
and the
.b \-q
flag says to just run every job in the queue.
If you have a tendency toward voyeurism,
you can use the
.b \-v
flag to watch what is going on.
.pp
When the queue is finally emptied,
you can remove the directory:
.(b
rmdir /var/spool/omqueue
.)b
.sh 2 "Disk Based Connection Information"
.pp
.i Sendmail
stores a large amount of information about each remote system it
has connected to in memory. It is now possible to preserve some
of this information on disk as well, by using the
.b HostStatusDirectory
option, so that it may be shared between several invocations of
.i sendmail .
This allows mail to be queued immediately or skipped during a queue run if
there has been a recent failure in connecting to a remote machine.
.pp
Additionally enabling
.b SingleThreadDelivery
has the added effect of single-threading mail delivery to a destination.
This can be quite helpful
if the remote machine is running an SMTP server that is easily overloaded
or cannot accept more than a single connection at a time,
but can cause some messages to be punted to a future queue run.
It also applies to
.i all
hosts, so setting this because you have one machine on site
that runs some software that is easily overrun
can cause mail to other hosts to be slowed down.
If this option is set,
you probably want to set the
.b MinQueueAge
option as well and run the queue fairly frequently;
this way jobs that are skipped because another
.i sendmail
is talking to the same host will be tried again quickly
rather than being delayed for a long time.
.pp
The disk based host information is stored in a subdirectory of the
.b mqueue
directory called
.b \&.hoststat \**.
.(f
\**This is the usual value of the
.b HostStatusDirectory
option;
it can, of course, go anywhere you like in your filesystem.
.)f
Removing this directory and its subdirectories has an effect similar to
the
.i purgestat
command and is completely safe.
The information in these directories can
be perused with the
.i hoststat
command, which will indicate the host name, the last access, and the
status of that access.
An asterisk in the left most column indicates that a
.i sendmail
process currently has the host locked for mail delivery.
.pp
The disk based connection information is treated the same way as memory based
connection information for the purpose of timeouts.
By default, information about host failures is valid for 30 minutes.
This can be adjusted with
the
.b Timeout.hoststatus
option.
.pp
The connection information stored on disk may be purged at any time
with the
.i purgestat
command or by invoking sendmail with the
.b \-bH
switch.
The connection information may be viewed with the
.i hoststat
command or by invoking sendmail with the
.b \-bh
switch.
.sh 2 "The Service Switch"
.pp
The implementation of certain system services
such as host and user name lookup
is controlled by the service switch.
If the host operating system supports such a switch
.i sendmail
will use the native version.
Ultrix, Solaris, and DEC OSF/1 are examples of such systems\**.
.(f
\**HP-UX 10 has service switch support,
but since the APIs are apparently not available in the libraries
.i sendmail
does not use the native service switch in this release.
.)f
.pp
If the underlying operating system does not support a service switch
(e.g., SunOS 4.X, HP-UX, BSD)
then
.i sendmail
will provide a stub implementation.
The
.b ServiceSwitchFile
option points to the name of a file that has the service definitions.
Each line has the name of a service
and the possible implementations of that service.
For example, the file:
.(b
hosts	dns files nis
aliases	files nis
.)b
will ask
.i sendmail
to look for hosts in the Domain Name System first.
If the requested host name is not found,
it tries local files,
and if that fails it tries NIS.
Similarly,
when looking for aliases
it will try the local files first
followed by NIS.
.pp
Service switches are not completely integrated.
For example, despite the fact that the host entry listed in the above example
specifies to look in NIS,
on SunOS this won't happen because the system implementation of
.i gethostbyname \|(3)
doesn't understand this.
If there is enough demand
.i sendmail
may reimplement
.i gethostbyname \|(3),
.i gethostbyaddr \|(3),
.i getpwent \|(3),
and the other system routines that would be necessary
to make this work seamlessly.
.sh 2 "The Alias Database"
.pp
After recipient addresses are read from the SMTP connection
or command line
they are parsed by ruleset 0,
which must resolve to a
{\c
.i mailer ,
.i host ,
.i address }
triple.
If the flags selected by the
.i mailer
include the
.b A
(aliasable) flag,
the
.i address
part of the triple is looked up as the key
(i.e., the left hand side)
into the alias database.
If there is a match, the address is deleted from the send queue
and all addresses on the right hand side of the alias
are added in place of the alias that was found.
This is a recursive operation,
so aliases found in the right hand side of the alias
are similarly expanded.
.pp
The alias database exists in two forms.
One is a text form,
maintained in the file
.i /etc/mail/aliases.
The aliases are of the form
.(b
name: name1, name2, ...
.)b
Only local names may be aliased;
e.g.,
.(b
eric@prep.ai.MIT.EDU: eric@CS.Berkeley.EDU
.)b
will not have the desired effect
(except on prep.ai.MIT.EDU,
and they probably don't want me)\**.
.(f
\**Actually, any mailer that has the `A' mailer flag set
will permit aliasing;
this is normally limited to the local mailer.
.)f
Aliases may be continued by starting any continuation lines
with a space or a tab or by putting a backslash directly before
the newline.
Blank lines and lines beginning with a sharp sign
(\c
.q # )
are comments.
.pp
The second form is processed by the
.i ndbm \|(3)\**
.(f
\**The
.i gdbm
package does not work.
.)f
or the Berkeley DB library.
This form is in the file
.i /etc/mail/aliases.db
(if using NEWDB)
or
.i /etc/mail/aliases.dir
and
.i /etc/mail/aliases.pag
(if using NDBM).
This is the form that
.i sendmail
actually uses to resolve aliases.
This technique is used to improve performance.
.pp
The control of search order is actually set by the service switch.
Essentially, the entry
.(b
O AliasFile=switch:aliases
.)b
is always added as the first alias entry;
also, the first alias file name without a class
(e.g., without
.q nis:
on the front)
will be used as the name of the file for a ``files'' entry
in the aliases switch.
For example, if the configuration file contains
.(b
O AliasFile=/etc/mail/aliases
.)b
and the service switch contains
.(b
aliases	nis files nisplus
.)b
then aliases will first be searched in the NIS database,
then in /etc/mail/aliases,
then in the NIS+ database.
.pp
You can also use
.sm NIS -based
alias files.
For example, the specification:
.(b
O AliasFile=/etc/mail/aliases
O AliasFile=nis:mail.aliases@my.nis.domain
.)b
will first search the /etc/mail/aliases file
and then the map named
.q mail.aliases
in
.q my.nis.domain .
Warning: if you build your own
.sm NIS -based
alias files,
be sure to provide the
.b \-l
flag to
.i makedbm (8)
to map upper case letters in the keys to lower case;
otherwise, aliases with upper case letters in their names
won't match incoming addresses.
.pp
Additional flags can be added after the colon
exactly like a
.b K
line \(em for example:
.(b
O AliasFile=nis:\-N mail.aliases@my.nis.domain
.)b
will search the appropriate NIS map and always include null bytes in the key.
Also:
.(b
O AliasFile=nis:\-f mail.aliases@my.nis.domain
.)b
will prevent sendmail from downcasing the key before the alias lookup.
.sh 3 "Rebuilding the alias database"
.pp
The
.i hash
or
.i dbm
version of the database
may be rebuilt explicitly by executing the command
.(b
newaliases
.)b
This is equivalent to giving
.i sendmail
the
.b \-bi
flag:
.(b
/usr/\*(SD/sendmail \-bi
.)b
.pp
If the
.b RebuildAliases
(old
.b D )
option is specified in the configuration,
.i sendmail
will rebuild the alias database automatically
if possible
when it is out of date.
Auto-rebuild can be dangerous
on heavily loaded machines
with large alias files;
if it might take more than the rebuild timeout
(option
.b AliasWait ,
old
.b a ,
which is normally five minutes)
to rebuild the database,
there is a chance that several processes will start the rebuild process
simultaneously.
.pp
If you have multiple aliases databases specified,
the
.b \-bi
flag rebuilds all the database types it understands
(for example, it can rebuild NDBM databases but not NIS databases).
.sh 3 "Potential problems"
.pp
There are a number of problems that can occur
with the alias database.
They all result from a
.i sendmail
process accessing the DBM version
while it is only partially built.
This can happen under two circumstances:
One process accesses the database
while another process is rebuilding it,
or the process rebuilding the database dies
(due to being killed or a system crash)
before completing the rebuild.
.pp
Sendmail has three techniques to try to relieve these problems.
First, it ignores interrupts while rebuilding the database;
this avoids the problem of someone aborting the process
leaving a partially rebuilt database.
Second,
it locks the database source file during the rebuild \(em
but that may not work over NFS or if the file is unwritable.
Third,
at the end of the rebuild
it adds an alias of the form
.(b
@: @
.)b
(which is not normally legal).
Before
.i sendmail
will access the database,
it checks to insure that this entry exists\**.
.(f
\**The
.b AliasWait
option is required in the configuration
for this action to occur.
This should normally be specified.
.)f
.sh 3 "List owners"
.pp
If an error occurs on sending to a certain address,
say
.q \fIx\fP ,
.i sendmail
will look for an alias
of the form
.q owner-\fIx\fP
to receive the errors.
This is typically useful
for a mailing list
where the submitter of the list
has no control over the maintenance of the list itself;
in this case the list maintainer would be the owner of the list.
For example:
.(b
unix-wizards: eric@ucbarpa, wnj@monet, nosuchuser,
	sam@matisse

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?