summaryrefslogtreecommitdiff
path: root/tools/qmail
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-06-02 16:07:44 (GMT)
committerJohn Denker <jsd@av8n.com>2012-06-03 00:30:23 (GMT)
commit32e75879103a943ac682cbde7b37ea4e4fbc24ab (patch)
treee734de5ec0cb5ece57d0f5aa01f6731a11f86a9b /tools/qmail
parent9c9c853dd2c7b4b174fd435d092bb43e737b8b35 (diff)
add some tools
Diffstat (limited to 'tools/qmail')
-rwxr-xr-xtools/qmail254
1 files changed, 254 insertions, 0 deletions
diff --git a/tools/qmail b/tools/qmail
new file mode 100755
index 0000000..9b715ee
--- /dev/null
+++ b/tools/qmail
@@ -0,0 +1,254 @@
+#! /bin/sh
+#
+# Qmail-init-script
+#
+# chkconfig: 2345 90 10
+# description: Qmail, the low-impact mail server.
+
+PATH="/var/qmail/bin:/usr/local/sbin:/usr/local/bin:$PATH"
+export PATH
+mailhost=0 ## bind to all addresses, including localhost and ether
+tcps=$( which tcpserver )
+
+qmaild=$(id -u qmaild )
+nofiles=$(id -g qmaild )
+smtpconf=/etc/stunnel/smtp.conf
+pop3conf=/etc/stunnel/pop3.conf
+
+## Plain smtp never asks for a password,
+## and will not relay except from inside the firewall.
+## in accordance with /etc/tcpserver/smtp.rules.
+
+## SMTPS will relay for anybody who has a password.
+
+## The firewall ensures that plain pop3 is
+## accessible only on local-area-network, inside the firewall.
+
+# The following can be overridden by command-line
+# environment setting, e.g. pop3s=no ./qmail start
+: ${CKPW:=/bin/qmaild/checkpassword}
+: ${PIDO:=/var/qmail/bin/pido}
+
+banner="Starting Qmail MTA:"
+test -n "$mailhost" || mailhost=$(hostname -f )
+
+
+proc_running(){
+ proc=$1
+ if test -f /var/run/$proc.pid ; then
+ pid=$( cat /var/run/$proc.pid )
+ if test -n "pid" && 2>/dev/null kill -0 $pid ; then
+ return 0
+ fi
+ fi
+ return 1
+}
+
+## Note that this will EXIT if the proc can't start
+## within ten seconds
+## cutting off any chance of continuing toward partial success.
+proc_ok(){
+ proc=$1
+ ii=0
+ while test $ii -lt 10 ; do
+ if proc_running $proc ; then
+ echo " ok."
+ return
+ else
+ echo -n .
+ sleep 1
+ fi
+ : $((ii += 1))
+ done
+
+ echo "failed!"
+ exit 1
+}
+
+stop_proc() {
+ proc="$1"
+ sign="$2"
+ proc_running $proc || return 0
+ pid=$( cat /var/run/$proc.pid )
+ echo -n "Stopping $proc ($pid): "
+ kill -15 $sign$pid
+ ii=0
+ while test $ii -lt 10 ; do
+ if proc_running $proc ; then
+ echo -n .
+ sleep 1
+ else
+ echo "stopped."
+ return
+ fi
+ : $((ii += 1))
+ done
+ echo "Ooops, still running ($pid)."
+}
+
+stop_all() {
+ flag="$1"
+ ## first, the fancy server daemons:
+ test -z "${smtp%%[Nn0]*}" || stop_proc qmail-smtp ""
+ test -z "${smtps%%[Nn0]*}" || stop_proc qmail-smtps ""
+ test -z "${pop3%%[Nn0]*}" || stop_proc qmail-pop3 ""
+ test -z "${pop3s%%[Nn0]*}" || stop_proc qmail-pop3s ""
+ test -z "${send%%[Nn0]*}" || stop_proc qmail-send "$flag"
+}
+
+
+
+verb="$1";
+if test "$#" -gt 0 ; then shift ; fi
+
+for thing in $* ; do
+ case $thing in
+ send) send=yes ;;
+ smtp) smtp=yes ;;
+ smtps) smtps=yes ;;
+ pop3) pop3=yes ;;
+ pop3s) pop3s=yes ;;
+ *) 1>&2 echo "Extraneous verbiage '$thing'" ; exit 1 ;;
+ esac
+done
+
+
+if test -n "${smtp%%[Nn0]*}${smtps%%[Nn0]*}${pop3%%[Nn0]*}${pop3s%%[Nn0]*}${send%%[Nn0]*}" ; then
+: ${default:=no}
+else
+: ${default:=yes}
+fi
+: ${send:=$default}
+: ${smtps:=$default}
+: ${pop3s:=$default}
+: ${pop3:=$default} ## FIXME: disable this ASAP.
+: ${smtp:=$default}
+
+
+flag=""
+case "$verb" in
+ restart)
+ $0 stop $@
+ $0 start $@
+ ;;
+ start)
+ if test -n "${send%%[Nn0]*}" ; then
+ test -n "$banner" && echo $banner ; banner=""
+ proc=qmail-send
+ if proc_running $proc ; then
+ 1>&2 echo " Oops, $proc is already running ($pid)."
+ else
+ echo -n " qmail-send: "
+ /bin/rm -f /var/run/$proc.pid
+ qmail-start ./Maildir/ splogger qmail >/dev/null 2>&1 &
+ echo $! > /var/run/$proc.pid
+ proc_ok $proc
+ fi
+ fi
+
+ if test -n "${smtp%%[Nn0]*}" ; then
+ test -n "$banner" && echo $banner ; banner=""
+ proc=qmail-smtp
+ if proc_running $proc ; then
+ 1>&2 echo " Oops, $proc is already running ($pid)."
+ else
+ echo -n " SMTP-server "
+ /bin/rm -f /var/run/$proc.pid
+ ## xxxQMAILQUEUE=/var/qmail/bin/hi-q \
+ $PIDO /var/run/$proc.pid \
+ $tcps -R -x/etc/tcpserver/smtp.cdb \
+ -u$qmaild -g$nofiles $mailhost smtp \
+ qmail-smtpd 2>&1 \
+ | splogger smtp &
+ proc_ok $proc
+ fi
+ fi
+
+ if test -n "${smtps%%[Nn0]*}" ; then
+ test -n "$banner" && echo $banner ; banner=""
+ proc=qmail-smtps
+ if proc_running $proc ; then
+ 1>&2 echo " Oops, $proc is already running ($pid)."
+ else
+ echo -n " SMTPS-server "
+ /bin/rm -f /var/run/$proc.pid
+ $PIDO /var/run/$proc.pid \
+ $tcps -R -u$qmaild -g$nofiles $mailhost smtps \
+ stunnel $smtpconf 2>&1 \
+ | splogger smtps &
+ proc_ok $proc
+ fi
+ fi
+
+
+ if test -n "${pop3%%[Nn0]*}" ; then
+ test -n "$banner" && echo $banner ; banner=""
+ proc=qmail-pop3
+ if proc_running $proc ; then
+ 1>&2 echo " Oops, $proc is already running ($pid)."
+ else
+ echo -n " POP3-server "
+ /bin/rm -f /var/run/$proc.pid
+ $PIDO /var/run/$proc.pid \
+ $tcps -v -p -R $mailhost pop3 qmail-popup $mailhost \
+ $CKPW qmail-pop3d Maildir 2>&1 \
+ | splogger pop3 &
+ proc_ok $proc
+ fi
+ fi
+
+ if test -n "${pop3s%%[Nn0]*}" ; then
+ test -n "$banner" && echo $banner ; banner=""
+ proc=qmail-pop3s
+ if proc_running $proc ; then
+ 1>&2 echo " Oops, $proc is already running ($pid)."
+ else
+ echo -n " POP3S-server "
+ /bin/rm -f /var/run/$proc.pid
+ $PIDO /var/run/$proc.pid \
+ $tcps -v -p -R $mailhost pop3s \
+ stunnel $pop3conf 2>&1 | \
+ splogger pop3s &
+ proc_ok $proc
+ fi
+ fi
+ ;;
+
+ zap)
+ stop_all "-"
+ ;;
+
+ stop)
+ stop_all ""
+ ;;
+
+## cause qmail-send to reread a couple of control files:
+ reload)
+ echo -n "Reread control/locals, control/rcpthosts, and control/virtualdomains: "
+ if kill -1 $( cat /var/run/qmail-send.pid ) ; then
+ echo " ok."
+ else
+ echo " failed."
+ fi
+ ;;
+ status)
+ for thing in send smtp smtps pop3 pop3s ; do
+ xthing="qmail-$thing"
+ printf "%-12s : " "$xthing"
+ pid=$( cat /var/run/$xthing.pid 2>/dev/null )
+ : ${pid:=xxx}
+ if kill -0 "$pid" 2>/dev/null ; then
+ echo " up. $pid"
+ else
+ echo " down. $pid"
+ fi
+ done
+ if ! test -r '/etc/tcpserver/smtp.cdb' ; then
+ echo "Beware: /etc/tcpserver/smtp.cdb is missing."
+ fi
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|reload|zap|restart|status}"
+ exit 1
+ ;;
+esac