qmail Toaster Recovery

Ok, here is another one that was specifically geared to my setup, but I thought it may help someone else out in a pinch. I lost the motherboard for my web/email server due to that “capacitor problem”. What follows is how I got everything back up and functional. The server consisted of Apache and qmail, plus various other odds and ends. Another item to note is that this is a FreeBSD 5.1-RELEASE system, linux admins change settings accordingly.

First, I get the basics on there so I have network connectivity and the tools I use to make everything go smoothly, not to mention there are some security issues involved.

1. install cvsup-without-gui

2. create /usr/src/sup-ports
*default host=cvsup8.FreeBSD.org
*default base=/usr
*default prefix=/usr
*default release=cvs tag=.
# date=2003.03.25.23.00.00
*default delete use-rel-suffix
*default compress
ports-all

3. cvsup ports

4. install portsupgrade

5. install apache2

6. install mod_php4 (sockets and bcmath)

7. install bind9

8. configure DHCPd
isc-dhcp3 port

Did I forget to mention that this server was also my DHCPd server for the LAN?

9. install irssi

10. install lynx

11. install ntp

12. install openssl (overwrite_base)

13. install opensshportable (point rc.conf to new binary)

14. install screen

15. install mget

16. install zsh (it’s just my preference, thanks stibnite)

Now, we’ll get into the qmail (and vpopmail) install so I can start spooling email locally instead of letting my secondary take care of all the work. As I mentioned before, I use qmail… again, thanks stib. Some of the following items were taken verbatim from Flattie’s qmail toaster howto. I could provide a link, but thats why you have google bookmarked.

1. create users and groups for qmail and vpopmail (this may not be required when using the freebsd port but I did it before hand anyway)

mkdir /var/qmail
pw groupadd -n vchkpw -g 98
pw useradd -n vpopmail -u 98 -g 98 -c Vpopmail-Master -d /home/vpopmail -s /nonexistent (all on one line)
pw groupadd -n nofiles -g 91
pw groupadd -n qmail -g 92
pw useradd -n alias -u 91 -g 91 -d /var/qmail/alias -s /nonexistent
pw useradd -n qmaild -u 92 -g 91 -d /var/qmail -s /nonexistent
pw useradd -n qmaill -u 93 -g 91 -d /var/qmail -s /nonexistent
pw useradd -n qmailp -u 94 -g 91 -d /var/qmail -s /nonexistent
pw useradd -n qmailq -u 95 -g 92 -d /var/qmail -s /nonexistent
pw useradd -n qmailr -u 96 -g 92 -d /var/qmail -s /nonexistent
pw useradd -n qmails -u 97 -g 92 -d /var/qmail -s /nonexistent

2. make directories

mkdir /var/log/qmail
mkdir /var/log/qmail/qmail-send
mkdir /var/log/qmail/qmail-smtpd
mkdir /var/log/qmail/qmail-pop3d
chown -R qmaill.wheel /var/log/qmail
chmod -R 750 /var/log/qmail

3. cd /usr/ports/mail/qmail

make fetch
make patch
download eric johnstons smtpd-auth patch
patch according to the included INSTALL document
vi ./work/qmail*/conf-split change 23 > 199
vi ./work/qmail*/conf-spawn change 120 > 255
make install clean
echo 255 > /var/qmail/control/concurrencyremote
chmod 644 /var/qmail/control/concurrencyremote

4. cd /usr/ports/sysutils/daemontools
make install clean

5. cd /usr/ports/sysutils/ucspi-tcp
make install clean

6. vi /etc/tcp.smtp

127.0.0.1:allow,RELAYCLIENT=””
10.1.1.1-252:allow,RELAYCLIENT=””
:allow

/usr/local/bin/tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp &1 > /dev/null

11. cd /usr/ports/mail/autorespond
make install clean

12. install gdbm /usr/ports/databases/gdbm
make install clean

13. check for files in /var/qmail/control
(restore rcpthosts, virtualdomains, /home/vpopmail/domains and users dir)
(remember to re-chmod if necessary)
If you are actually using this document to help you do a restore and didn’t do a backup, yer fooked.

14. edit rc.conf
sendmail_enable=”NONE”

15. edit /etc/mail/mailer.conf
sendmail /var/qmail/bin/sendmail
send-mail /var/qmail/bin/sendmail

Create the file structure for daemontools to run its qmail scripts:

mkdir /service
chmod 755 /service
mkdir /var/qmail/supervise
chmod 755 /var/qmail/supervise

mkdir /var/qmail/supervise/qmail-smtpd
mkdir /var/qmail/supervise/qmail-smtpd/log
chmod +t /var/qmail/supervise/qmail-smtpd

mkdir /var/qmail/supervise/qmail-send
mkdir /var/qmail/supervise/qmail-send/log
chmod +t /var/qmail/supervise/qmail-send

mkdir /var/qmail/supervise/qmail-pop3d
mkdir /var/qmail/supervise/qmail-pop3d/log
chmod +t /var/qmail/supervise/qmail-pop3d

ln -s /var/qmail/supervise/* /service/

ls -la /service/

OUTPUT:
lrwx—— 1 root wheel 32 Jan 01 00:00 qmail-pop3d@ -> /var/qmail/supervise/qmail-pop3d
lrwx—— 1 root wheel 31 Sep 01 00:00 qmail-send@ -> /var/qmail/supervise/qmail-send
lrwx—— 1 root wheel 32 Sep 01 00:00 qmail-smtpd@ -> /var/qmail/supervise/qmail-smtpd

SUPERVISION SCRIPTS

Create the supervision scripts that keep everything from dying.

1. vi /var/qmail/rc

#!/bin/sh
env env – PATH=”/var/qmail/bin:/usr/local/bin” \
qmail-start ./Maildir/

chmod 700 /var/qmail/rc

2. vi /var/qmail/supervise/qmail-pop3d/run

#!/bin/sh
exec /usr/local/bin/tcpserver -H -R -v -c100 0 110 /var/qmail/bin/qmail-popup mail-host1.domain.org \
/home/vpopmail/bin/vchkpw /var/qmail/bin/qmail-pop3d Maildir 2>&1

chmod 755 /var/qmail/supervise/qmail-pop3d/run

3. vi /var/qmail/supervise/qmail-pop3d/log/run

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t s100000 n20 /var/log/qmail/qmail-pop3d 2>&1

chmod 755 /var/qmail/supervise/qmail-pop3d/log
chmod 755 /var/qmail/supervise/qmail-pop3d/log/run

4. vi /var/qmail/supervise/qmail-smtpd/run

#!/bin/sh
exec /usr/local/bin/tcpserver -p -R -x /etc/tcp.smtp.cdb -u92 -g91 -v -c100 0 smtp rblsmtpd /var/qmail/bin/qmail-smtpd 2>&1

chmod 755 /var/qmail/supervise/qmail-smtpd/run

5. vi /var/qmail/supervise/qmail-smtpd/log/run

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t s100000 n20 /var/log/qmail/qmail-smtpd 2>&1

chmod 755 /var/qmail/supervise/qmail-smtpd/log
chmod 755 /var/qmail/supervise/qmail-smtpd/log/run

6. vi /var/qmail/supervise/qmail-send/run

#!/bin/sh
exec /var/qmail/rc

chmod 755 /var/qmail/supervise/qmail-send/run

7. vi /var/qmail/supervise/qmail-send/log/run

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t s100000 n20 /var/log/qmail/qmail-send 2>&1

chmod 755 /var/qmail/supervise/qmail-send/log
chmod 755 /var/qmail/supervise/qmail-send/log/run

QMAIL RC SCRIPT

Create the qmail rc script if its not already present due to the port install

1. vi /usr/local/etc/rc.d/qmail

#!/bin/sh
case “$1″ in
start)
echo -n “Starting qmail: svscan”
if cd /var/qmail/supervise; then
env – PATH=”/var/qmail/bin:/usr/local/bin:/usr/bin:/bin” svscan &
echo $! > /var/run/svscan.pid
fi
echo “.”
;;
stop)
echo -n “Stopping qmail: svscan”
kill `cat /var/run/svscan.pid`
echo -n ” qmail”
svc -dx /var/qmail/supervise/*
echo -n ” logging”
svc -dx /var/qmail/supervise/*/log
echo “.”
;;
stat)
cd /var/qmail/supervise
svstat * */log
;;
doqueue|alrm)
echo “Sending ALRM signal to qmail-send.”
svc -a /var/qmail/supervise/qmail-send
;;
queue)
qmail-qstat
qmail-qread
;;
reload|hup)
echo “Sending HUP signal to qmail-send.”
svc -h /var/qmail/supervise/qmail-send
echo “Sending HUP signal to qmail-pop3d.”
svc -h /var/qmail/supervise/qmail-pop3d
;;
pause)
echo “Pausing qmail-send”
svc -p /var/qmail/supervise/qmail-send
echo “Pausing qmail-smtpd”
svc -p /var/qmail/supervise/qmail-smtpd
echo “Pausing qmail-pop3d”
svc -p /var/qmail/supervise/qmail-pop3d
;;
cont)
echo “Continuing qmail-send”
svc -c /var/qmail/supervise/qmail-send
echo “Continuing qmail-smtpd”
svc -c /var/qmail/supervise/qmail-smtpd
echo “Continuing qmail-pop3d”
svc -c /var/qmail/supervise/qmail-pop3d
;;
restart)
echo “Restarting qmail:”
echo “* Stopping qmail-smtpd.”
svc -d /var/qmail/supervise/qmail-smtpd
echo “* Sending qmail-send SIGTERM and restarting.”
svc -t /var/qmail/supervise/qmail-send
echo “* Restarting qmail-smtpd.”
svc -u /var/qmail/supervise/qmail-smtpd
echo “* Sending qmail-pop3d SIGTERM and restarting.”
svc -t /var/qmail/supervise/qmail-pop3d
;;
cdb)
tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp &1 > /dev/null

That should do it.

I’m sure I missed a few steps or software installs in there somewhere. If I did, don’t come crying to me, that’s what your mamma is for. After you’re done crying, feel free to drop me a line and tell me what I missed, thanks.

This entry was posted in Daemons, FreeBSD, OS, smtp and tagged , , , . Bookmark the permalink.

Comments are closed.