6152d12
#!/bin/bash
6152d12
#
6152d12
# opensmtpd  This shell script takes care of starting and stopping
6152d12
#            OpenSMTPD on RedHat or other chkconfig-based system.
6152d12
#
6152d12
# chkconfig: 2345 80 30
6152d12
# processname: smtpd
6152d12
# config: /etc/opensmtpd/smtpd.conf
6152d12
# pidfile: /var/run/smtpd.pid
6152d12
#
6152d12
# description: OpenSMTPD is a Mail Transport Agent, which is the program \
6152d12
#              that moves mail from one machine to another.
6152d12
6152d12
### BEGIN INIT INFO
6152d12
# Provides: opensmtpd
6152d12
# Required-Start: $network
6152d12
# Required-Stop: $network
6152d12
# Default-Start: 2 3 4 5
6152d12
# Default-Stop: 0 1 6
6152d12
# Short-Description: start and stop opensmtpd
6152d12
# Description: OpenSMTPD is a Mail Transport Agent, which is the program \
6152d12
#              that moves mail from one machine to another.
6152d12
### END INIT INFO
6152d12
6152d12
# Contributed by Denis Fateyev <denis@fateyev.com>
6152d12
# 2013.06.08
6152d12
6152d12
# Source function library
6152d12
. /etc/init.d/functions
6152d12
6152d12
# Source networking configuration
6152d12
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
6152d12
6152d12
start() {
6152d12
	[ "$EUID" != "0" ] && exit 4
6152d12
	[ "${NETWORKING}" = "no" ] && exit 1
6152d12
	[ -f /usr/sbin/smtpd ] || exit 5
6152d12
6152d12
        # Start daemon
6152d12
        echo -n $"Starting opensmtpd: "
6152d12
        /usr/sbin/smtpd && success || failure
6152d12
        RETVAL=$?
6152d12
        echo
6152d12
        [ $RETVAL = 0 ] && touch /var/lock/subsys/smtpd
6152d12
}
6152d12
6152d12
stop() {
6152d12
	[ "$EUID" != "0" ] && exit 4
6152d12
6152d12
        # Stop daemon
6152d12
        echo -n $"Shutting down opensmtpd: "
6152d12
        if [ -n "`pidfileofproc smtpd`" ] ; then
6152d12
	    /usr/sbin/smtpctl stop > /dev/null 2>&1 && success || failure
6152d12
	else
6152d12
	    failure $"Shutting down opensmtpd"
6152d12
	fi
6152d12
	RETVAL=$?
6152d12
        echo
6152d12
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/smtpd
6152d12
}
6152d12
6152d12
restart() {
6152d12
	stop
6152d12
	start
6152d12
}
6152d12
6152d12
# See how we were called
6152d12
case "$1" in
6152d12
  start)
6152d12
	start
6152d12
	;;
6152d12
  stop)
6152d12
	stop
6152d12
	;;
6152d12
  restart)
6152d12
	restart
6152d12
	;;
6152d12
  condrestart|try-restart)
6152d12
	status smtpd > /dev/null || exit 0
6152d12
	restart
6152d12
	;;
6152d12
  status)
6152d12
	status smtpd
6152d12
	;;
6152d12
  *)
6152d12
	echo $"Usage: $0 {start|stop|restart|status|condrestart|try-restart}"
6152d12
	exit 2
6152d12
esac
6152d12
6152d12
exit $RETVAL