#! /bin/sh
#
# This is /etc/rc.d/init.d file for Q-Mail
#
# chkconfig: 345 80 30
# description: qmail Mail Transfer Agent
# processname: qmail-send
#
#
### BEGIN INIT INFO
# Provides: sendmail qmail
# Required-Start: $network $named $syslog $remote_fs $time
# X-UnitedLinux-Should-Start:
# Required-Stop:
# Default-Start: 3 5
# Default-Stop:
# Description: start the qmail MTA
### END INIT INFO
# Source networking configuration.
if [ -f /etc/sysconfig/network ]; then
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
fi
# Source function library.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi
# this way is for SuSE Linux
test -s /etc/rc.status && . /etc/rc.status && rc_reset
if ! type status >/dev/null 2>/dev/null; then
status () {
pidof >/dev/null qmail-send
}
fi
# pidofproc does not exist on Debian linux
if ! type pidofproc >/dev/null 2>/dev/null; then
# A function to find the pid of a program.
pidofproc() {
base=${1##*/}
# Test syntax.
if [ "$#" = 0 ]; then
echo $"Usage: pidofproc {program}"
return 1
fi
# First try "/var/run/*.pid" files
if [ -f /var/run/$base.pid ]; then
local line p pid=
read line < /var/run/$base.pid
for p in $line ; do
[ -z "echo $p | tr -d '[0-9]'" -a -d /proc/$p ] && pid="$pid $p"
done
if [ -n "$pid" ]; then
echo $pid
return 0
fi
fi
pidof -o $$ -o $PPID -o %PPID -x $1 || \
pidof -o $$ -o $PPID -o %PPID -x $base
}
fi
myname=qmail
qmail_dir=/var/qmail
subsys=/var/lock/subsys/$myname
PATH="$qmail_dir/bin:$PATH"
export PATH
proccess=qmail-send
# this function is designed to emulate RedHat-like service reporting on the SuSE Linux
report_action()
{
# $1 - text to put
# $2 - status of operation
case `type -t action` in
function)
# red hat operation reporting style
action $"$1" $2
;;
*)
case `type -t rc_reset` in
function)
# suse linux reporting style
rc_reset
echo -n $"$1"
$2
rc_status -v
;;
*)
# debian style, probably useful for other systems
echo -n $"$1"
$2
if [ $? -eq 0 ]; then
echo "done"
else
echo "failed"
fi
;;
esac
;;
esac
}
start()
{
if [ -x /sbin/start-stop-daemon -a ! -d "`dirname $subsys`" ]; then
# use debian daemon control facility
sh -c "start-stop-daemon --start --quiet --user qmails \
--exec ${qmail_dir}/bin/qmail-send \
--startas ${qmail_dir}/bin/qmail-start -- ./Maildir/ splogger qmail 2 &"
else
qmail-start ./Maildir/ splogger qmail &
fi
sleep 1
pidofproc $proccess >/dev/null 2>&1
ret=$?
if [ "$ret" -eq 0 ]; then
report_action "Starting $myname: " /bin/true
else
report_action "Starting $myname: " /bin/false
fi
[ "$ret" -eq 0 ] && [ -d "`dirname $subsys`" ] && touch $subsys
return "$ret"
}
check_and_start()
{
if [ ! -f $subsys ]; then
start
fi
}
stop()
{
if [ -f $subsys ]; then
echo -n $"Stopping $prog: "
killproc $proccess > /dev/null 2>&1
else
if [ -x /sbin/start-stop-daemon -a ! -d "`dirname $subsys`" ]; then
# use debian daemon control facility
start-stop-daemon --user qmails --stop --quiet --oknodo --exec ${qmail_dir}/bin/qmail-send
else
killall $proccess >/dev/null 2>&1
fi
fi
[ -f "$subsys" ] && rm -f "$subsys"
for i in 1 1 1 1 1 5 10 10 10 10 10; do
pidofproc $proccess >/dev/null 2>&1
[ 0 -ne "$?" ] && return 0
sleep $i
done
for i in qmail-remote.moved qmail-send; do
killall $i
sleep 1
killall -9 $i
sleep 1
done >/dev/null 2>&1
pidofproc $proccess >/dev/null 2>&1
return $?
}
restart(){
stop
start
}
condrestart(){
[ -e $subsys ] && restart || true
}
#reload(){
# [ -e /var/lock/subsys/$myname ] && mysqladmin reload
#}
# See how we were called.
case "$1" in
start)
start
;;
condstart)
check_and_start
;;
stop)
stop
;;
status)
status $proccess
;;
reload)
restart
# reload
;;
restart)
restart
;;
condrestart)
condrestart
;;
force-reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|reload|condrestart|restart}"
exit 1
esac
exit $?