4.4 Starting and Stopping Qmail

Starting qmail is easy in principle. You run qmail-start and it starts the four communicating daemons that qmail needs. Two details complicate the situation: the default delivery instructions, and connecting the daemons to whatever you want to use for logging.

Because the daemontools package of which supervise is a part wasn't written until after qmail 1.03 was released, all of the provided startup files use splogger to send the log information to syslog. I find daemontools greatly preferable, so I primarily discuss how to set up qmail using supervise.

4.4.1 Choosing a Startup File

Qmail 1.03 comes with a selection of startup files you can use, either directly or as a starting point for a customized startup file of your own. You can find the startup files in /var/qmail/boot. None of them are usable directly with daemontools, but they're useful as templates. The differences among them only affect what happens when mail is delivered to a user who has no .qmail file, because the only difference is the string to use as a default .qmail. They include:


binm1

Default delivery using /usr/libexec/mail.local, the 4.4BSD mail delivery agent, which puts mail in /var/spool/mail


binm1+df

Same as binm1, also providing dot-forward emulation


binm2

Default delivery using /bin/mail with SVR4 flags, which also puts mail in /var/spool/mail


binm2+df

Same as binm2, also providing dot-forward emulation


binm3

Default delivery using /bin/mail with flags for older versions of Unix; puts mail in /var/spool/mail


binm3+df

Same as binm3, also providing dot-forward emulation


home

Default delivery using qmail's internal qmail-local, which puts mail in the user's Mailbox


home+df

Same as home, also providing dot-forward emulation


proc

Default delivery using procmail, which puts mail wherever procmail puts it, usually /var/spool/mail unless you patch procmail as I describe later


proc+df

Same as proc, also providing dot-forward emulation

Which flavor of startup depends mostly on your existing mail configuration. If you use procmail, keep using it. If you have a lot of users with .forward files, use a dot-forward version. (If you only have a few .forward files, it's easier to hand-translate them into .qmail files.) I don't recommend using any of the old mail delivery programs unless you really, really want to keep delivering mail in /var/mail. For testing and usually for production, I suggest either plain home-directory mailbox delivery or procmail.

Assuming that you've installed and started daemontools as suggested earlier in this chapter, you now must create a pair of supervise directories for qmail. I use /var/qmail/supervise/qmail-send and /var/qmail/supervise/qmail-send/log to be consistent with the widely used qmail setup instructions at http://www.lifewithqmail.org. Create them like this (as the super-user, which is why the following command lines start with a # prompt):

# mkdir /var/qmail/supervise/qmail-send # mkdir /var/qmail/supervise/qmail-send/log # chown root /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-send/log       # mkdir /var/qmail/supervise/qmail-send/log/main # chown qmaill /var/qmail/supervise/qmail-send/log/main

The log directory contains a subdirectory main that contains the actual logs. It belongs to qmaill, the qmail log pseudo-user.

Then create run files in both the main qmail and log directories, as in Example 4-1.

Example 4-1. qmail run
1. #!/bin/sh 2. 3.  limit open 1000 4.  limit maxproc 100 5.  6.  exec env - PATH="/var/qmail/bin:$PATH" \ 7.   qmail-start ./Mailbox

The two limit commands on lines 3 and 4 ensure that qmail can run many deliveries in parallel. Set maxproc to be larger than the number of parallel remote deliveries permitted. (By default the number of deliveries is 20, but you'll probably want to increase it unless you have a very slow or overloaded network connection, or handle a very small amount of mail.) Also set open, the per process open-file limit, to be at least twice the greater of the number of simultaneous local or remote deliveries permitted, because qmail-lspawn and qmail-rspawn use two pipes per delivery subprocess. Then the exec env command on line 6 clears out the environment, sets PATH to a known value, and runs qmail-start. The argument to qmail-start is copied from the example in /var/qmail/boot/home to default deliveries to Mailbox in a user's home directory. (You can copy the startup command from one of the other example files, such as boot/proc.)

Also create log/run to start up the logging process, as in Example 4-2.

Example 4-2. qmail log/run
 1. #!/bin/sh  2.   exec setuidgid qmaill \  3.   multilog t s4000000 ./main

The setuidgid command switches to the qmail log pseudo-user, then runs multilog to store qmail's output into rotating log files. The arguments say to prefix each line with a time stamp, and to create log files of up to 4 MB in the subdirectory main.

Supervise starts the run scripts directly, so they need to be executable:

# chmod +x /var/qmail/supervise/qmail-send/run # chmod +x /var/qmail/supervise/qmail-send/log/run

Be sure the initial #!/bin/sh line is present in each of the scripts so they are self-running.

4.4.2 Fire `er Up

Once you've created the run files, it's time to start qmail:

# ln -s /var/qmail/supervise/qmail-send /service

Assuming you have svscan running, within a few seconds of making the line, qmail will start. Look at the log file /var/qmail/supervise/qmail-send/log/main/current to be sure. It should contain a line similar to this:

status: local 0/10 remote 0/20

Now try telling qmail to send some local mail:

$ /var/qmail/bin/qmail-inject To: me       my first qmail message ^D

(Use your own username instead of me, of course.) The log file should now contain lines logging the local delivery:

new msg 175283 info msg 175283: bytes 230 from <fred@example.com> qp 5524 uid 100 starting delivery 1: msg 175283 to local fred@example.com status: local 1/10 remote 0/20 delivery 2: success: did_0+0+1/ status: local 0/10 remote 0/20 end msg 175283

Your file Mailbox should contain the message. If not, the log should contain evidence of the problem, which is usually files or directories not created with the correct owner or permissions.

Now try a message to a nonexistent address:

$ /var/qmail/bin/qmail-inject  To: baduser       oops ^D

In this case, qmail attempts to deliver the message, then finds it can't and sends back a failure notice, which should end up in your mailbox. The log should look like this:

new msg 175283 info msg 175283: bytes 212 from <fred@example.com> qp 5690 uid 100 starting delivery 1: msg 175283 to local baduser@example.com status: local 1/10 remote 0/20 delivery 1: failure: Sorry,_no_mailbox_here_by_that_name._(#5.1.1)/ status: local 0/10 remote 0/20 bounce msg 175283 qp 5695 end msg 175283 new msg 175284 info msg 175284: bytes 746 from <> qp 5695 uid 124 starting delivery 2: msg 175284 to local fred@example.com status: local 1/10 remote 0/20 delivery 2: success: did_0+0+1/ status: local 0/10 remote 0/20 end msg 175284

Finally, try a test message to a mailbox on a remote system. If you don't have a remote mailbox handy, use the author's autoresponder at qmail@gurus.com. (It will send a response message telling you how clever you were to write to it, with a blurb for my books.)

$ /var/qmail/bin/qmail-inject  To: qmail@gurus.com       boing ^D

The logs show the remote delivery, including the IP address of the remote system and the remote system's response:

new msg 175283 info msg 175283: bytes 223 from <me@example.com> qp 6808 uid 100 starting delivery 3: msg 175283 to remote qmail@gurus.com status: local 0/10 remote 1/20 delivery 3: success: 208.31.42.43_accepted_message./Remote_host_said:_250_ok_ 993021663_qp_16918/ status: local 0/10 remote 0/20 end msg 175283

If all three of these tests work, you have correctly installed qmail. Congratulations!

4.4.3 Stopping Qmail

When you're running qmail for real, you'll almost never want to stop it, but when debugging, just tell supervise to stop qmail and mark it as down:

# svc -td /service/qmail-send

If there are deliveries in progress, qmail will wait for them to finish or time out. Then it exits. Use svc -u to bring qmail back up.



qmail
qmail
ISBN: 1565926285
EAN: 2147483647
Year: 2006
Pages: 152

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net