#! /bin/sh # # Author: # Guilherme Balena Versiani, guibv@yahoo.com # # /usr/sbin/qmailctl . /etc/qmail2.rc.config . /etc/qmail2.permissions SEND=qmail-send2 SMTP=qmail-smtpd2 POP3=qmail-pop3d2 QMQP=qmail-qmqpd2 QMTP=qmail-qmtpd2 QMAILBIN=/var/qmail2 SERVICES="$SEND $SMTP $POP3 $QMQP $QMTP" qmail_start() { for service in $SERVICES; do if [ -e /service/$service ]; then if svok /service/$service; then echo -n "$service " svc -u /service/$service else echo -n "$service [error] " fi fi done if [ -d /var/run/subsys ]; then touch /var/lock/subsys/qmail2 fi } qmail_stop() { for service in $SERVICES; do if [ -e /service/$service ]; then echo -n "$service " svc -d /service/$service fi done if [ -f /var/lock/subsys/qmail2 ]; then rm -f /var/lock/subsys/qmail2 fi } qmail_restart() { $0 stop && $0 start } qmail_pause() { for service in $SERVICES; do if [ -e /service/$service ]; then echo -n "$service " svc -p /service/$service fi done } qmail_continue() { for service in $SERVICES; do if [ -e /service/$service ]; then echo -n "$service " svc -c /service/$service fi done } qmail_status() { for service in $SERVICES; do if [ -e /service/$service ]; then svstat /service/$service svstat /service/$service/log fi done $QMAILBIN/qmail-qstat } qmail_flush() { if [ -e /service/$SEND ]; then svc -a /service/$SEND echo "OK" else echo "No qmail-send found!" fi } qmail_reload() { $QMAILBIN/qmail-qstat $QMAILBIN/qmail-qread } qmail_user() { for I in _0 _1 _2 _3 _4 _5 _6; do eval CUR_USER=\$QMAIL_USER$I USER=`echo "$CUR_USER" | cut -d ':' -f 1` grep "$USER" /etc/passwd > /dev/null && userdel $USER done for I in _0 _1; do eval CUR_GROUP=\$QMAIL_GROUP$I GROUP=`echo "$CUR_GROUP" | cut -d ':' -f 1` grep "$GROUP" /etc/group > /dev/null && groupdel $GROUP done for I in _0 _1; do eval CUR_GROUP=\$QMAIL_GROUP$I GROUP=`echo "$CUR_GROUP" | cut -d ':' -f 1` CGID=`echo "$CUR_GROUP" | cut -d ':' -f 2` groupadd -g $CGID $GROUP done for I in _0 _1 _2 _3 _4 _5 _6; do eval CUR_USER=\$QMAIL_USER$I USER=`echo "$CUR_USER" | cut -d ':' -f 1` CUID=`echo "$CUR_USER" | cut -d ':' -f 2` GROUP=`echo "$CUR_USER" | cut -d ':' -f 3` HOME=`echo "$CUR_USER" | cut -d ':' -f 4` useradd -u $CUID -g $GROUP -d $HOME -s /bin/false $USER done } qmail_showctl() { $QMAILBIN/qmail-showctl } usage() { cat << EOF Qmailctl by Guilherme Balena Versiani * Portions from Life with Qmail (http://www.lifewithqmail.org/) Usage: $0 [OPTION] Available options: start Start all qmail services stop Stop all qmail services restart Restart all qmail services status Show qmail status showctl Show qmail control status flush Flush qmail queue queue Show qmail queue pause Pause all qmail services cont Continue all qmail services perms Check all qmail permissions user (Re)create all qmail users Mail bug reports and suggestions to . EOF } # First reset status of this service case "$1" in start) echo -n "Starting qmail: "; qmail_start; echo;; stop) echo -n "Shutting down qmail: "; qmail_stop; echo;; restart) qmail_restart;; status) echo "Checking qmail status: "; qmail_status;; showctl) qmail_showctl;; flush) echo "Sending ALRM signal to qmail-send: "; qmail_flush;; queue) echo "Listing qmail queue: "; qmail_queue;; pause) echo -n "Pausing qmail: "; qmail_pause; echo "";; cont) echo "Continuing qmail: "; qmail_continue; echo "";; user) echo -n "Checking qmail users/groups: "; qmail_user; echo "OK";; perms) echo -n "Checking qmail permissions: "; qmail_permissions; echo "OK";; *) usage; exit 1;; esac