290507
#!/bin/bash
290507
#
290507
# postfix      Postfix Mail Transfer Agent
290507
#
290507
# chkconfig: - 80 30
290507
# description: Postfix is a Mail Transport Agent, which is the program \
290507
#              that moves mail from one machine to another.
290507
# processname: master
290507
# pidfile: /var/spool/postfix/pid/master.pid
290507
# config: /etc/postfix/main.cf
290507
# config: /etc/postfix/master.cf
290507
#
290507
# Based on startup script from Simon J Mudd <sjmudd@pobox.com>
290507
# 25/02/99: Mostly s/sendmail/postfix/g by John A. Martin <jam@jamux.com>
290507
# 23/11/00: Changes & suggestions by Ajay Ramaswamy <ajayr@bigfoot.com>
290507
# 20/01/01: Changes to fall in line with RedHat 7.0 style
290507
# 23/02/01: Fix a few untidy problems with help from Daniel Roesen.
290507
290507
### BEGIN INIT INFO
290507
# Provides: postfix $mail-transfer-agent
290507
# Required-Start: $local_fs $network $remote_fs
290507
# Required-Stop: $local_fs $network $remote_fs
290507
# Short-Description: start and stop postfix
290507
# Description: Postfix is a Mail Transport Agent, which is the program that 
290507
#              moves mail from one machine to another.
290507
### END INIT INFO
290507
290507
# Source function library.
290507
. /etc/rc.d/init.d/functions
290507
290507
# Source networking configuration.
290507
. /etc/sysconfig/network
290507
290507
RETVAL=0
290507
prog="postfix"
290507
lockfile=/var/lock/subsys/$prog
290507
pidfile=/var/spool/postfix/pid/master.pid
290507
290507
ALIASESDB_STAMP=/var/lib/misc/postfix.aliasesdb-stamp
290507
290507
# Script to update chroot environment
290507
CHROOT_UPDATE=/etc/postfix/chroot-update
290507
290507
status -p $pidfile -l $(basename $lockfile) master >/dev/null 2>&1
290507
running=$?
290507
290507
conf_check() {
290507
    [ -x /usr/sbin/postfix ] || exit 5
290507
    [ -d /etc/postfix ] || exit 6
290507
    [ -d /var/spool/postfix ] || exit 5
290507
}
290507
290507
make_aliasesdb() {
290507
	if [ "$(/usr/sbin/postconf -h alias_database)" == "hash:/etc/aliases" ]
290507
	then
290507
		# /etc/aliases.db may be used by other MTA, make sure nothing
290507
		# has touched it since our last newaliases call
290507
		[ /etc/aliases -nt /etc/aliases.db ] ||
290507
			[ "$ALIASESDB_STAMP" -nt /etc/aliases.db ] ||
290507
			[ "$ALIASESDB_STAMP" -ot /etc/aliases.db ] || return
290507
		/usr/bin/newaliases
290507
		touch -r /etc/aliases.db "$ALIASESDB_STAMP"
290507
	else
290507
		/usr/bin/newaliases
290507
	fi
290507
}
290507
290507
start() {
290507
	[ "$EUID" != "0" ] && exit 4
290507
	# Check that networking is up.
290507
	[ ${NETWORKING} = "no" ] && exit 1
290507
	conf_check
290507
	# Start daemons.
290507
	echo -n $"Starting postfix: "
290507
	make_aliasesdb >/dev/null 2>&1
290507
	[ -x $CHROOT_UPDATE ] && $CHROOT_UPDATE
290507
	/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
290507
	RETVAL=$?
290507
	[ $RETVAL -eq 0 ] && touch $lockfile
290507
        echo
290507
	return $RETVAL
290507
}
290507
290507
stop() {
290507
	[ "$EUID" != "0" ] && exit 4
290507
	conf_check
290507
        # Stop daemons.
290507
	echo -n $"Shutting down postfix: "
290507
	/usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
290507
	RETVAL=$?
290507
	[ $RETVAL -eq 0 ] && rm -f $lockfile $pidfile
290507
	echo
290507
	return $RETVAL
290507
}
290507
290507
reload() {
290507
	conf_check
290507
	echo -n $"Reloading postfix: "
290507
	[ -x $CHROOT_UPDATE ] && $CHROOT_UPDATE
290507
	/usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
290507
	RETVAL=$?
290507
	echo
290507
	return $RETVAL
290507
}
290507
290507
abort() {
290507
	conf_check
290507
	/usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
290507
	return $?
290507
}
290507
290507
flush() {
290507
	conf_check
290507
	/usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
290507
	return $?
290507
}
290507
290507
check() {
290507
	conf_check
290507
	/usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
290507
	return $?
290507
}
290507
290507
# See how we were called.
290507
case "$1" in
290507
  start)
290507
	[ $running -eq 0 ] && exit 0
290507
	start
290507
	;;
290507
  stop)
290507
	[ $running -eq 0 ] || exit 0
290507
	stop
290507
	;;
290507
  restart|force-reload)
290507
	stop
290507
	start
290507
	;;
290507
  reload)
290507
	[ $running -eq 0 ] || exit 7
290507
	reload
290507
	;;
290507
  abort)
290507
	abort
290507
	;;
290507
  flush)
290507
	flush
290507
	;;
290507
  check)
290507
	check
290507
	;;
290507
  status)
290507
  	status -p $pidfile -l $(basename $lockfile) master
290507
	;;
290507
  condrestart)
290507
	[ $running -eq 0 ] || exit 0
290507
	stop
290507
	start
290507
	;;
290507
  *)
290507
	echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
290507
	exit 2
290507
esac
290507
290507
exit $?