Sophie

Sophie

distrib > Mandriva > 2006.0 > i586 > media > main-src > by-pkgid > 7620026e54ba64521f9d312e97c922fe > files > 27

postfix-2.2.5-7mdk.src.rpm

#!/bin/sh
#
# postfix      Postfix Mail Transfer Agent
#
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.
# processname: master
# pidfile: /var/spool/postfix/pid/master.pid
# config: /etc/postfix/main.cf
# config: /etc/postfix/master.cf
#
# Based on startup script from Simon J Mudd <sjmudd@pobox.com>
# 25/02/99: Mostly s/sendmail/postfix/g by John A. Martin <jam@jamux.com>
# 23/11/00: Changes & suggestions by Ajay Ramaswamy <ajayr@bigfoot.com>
# 20/01/01: Changes to fall in line with RedHat 7.0 style
# 23/02/01: Fix a few untidy problems with help from Daniel Roesen.
# 25/04/01: Fix map creation algorithm

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x /usr/sbin/postfix ] || exit 0
[ -d /etc/postfix ] || exit 0
[ -d /var/spool/postfix ] || exit 0

RETVAL=0
UA=/usr/sbin/update-alternatives

# http://archives.mandrivalinux.com/cooker/2005-07/msg01012.php
# http://archives.mandrivalinux.com/cooker/2005-07/msg01691.php
fix_alternatives() {
	if [ -e /var/lib/rpm/alternatives/mta ]; then
		echo -n "Found old alternatives, fixing: "
		$UA --remove mta /usr/sbin/sendmail.postfix
		if [ -e /var/lib/rpm/alternatives/sendmail-command ]; then
			$UA --auto sendmail-command
		fi
		if [ ! -e /usr/bin/mailq ]; then
			ln -sf /usr/sbin/sendmail.postfix /usr/bin/mailq
		fi
		if [ ! -e /usr/bin/newaliases ]; then
			ln -sf /usr/sbin/sendmail.postfix /usr/bin/newaliases
		fi
		if [ ! -e /usr/bin/rmail ]; then
			cat > /usr/bin/rmail <<EOF
#!/bin/sh

# Dummy UUCP rmail command for postfix/qmail systems

SENDMAIL="/usr/sbin/sendmail"
IFS=" " read junk from junk junk junk junk junk junk junk relay

case "$from" in
 *[@!]*) ;;
      *) from="$from@$relay";;
esac

exec $SENDMAIL -i -f "$from" -- "$@"
EOF
		fi
		if [ ! -e /var/lib/rpm/alternatives/mta -a \
		  -e /usr/bin/mailq -a \
		  -e /usr/bin/newaliases -a \
		  -e /usr/bin/rmail ]; then
			echo_success
		else
			echo_failure
		fi
		echo
	fi
}
		

start() {
	fix_alternatives
	echo -n "Starting postfix: "
	# refresh chroot
	/usr/sbin/postfix-chroot.sh -q check_update
	# refresh aliases
	d=`postconf -h config_directory`
	for i in `(/usr/sbin/postconf;cat $d/main.cf $d/master.cf) | perl -ne '
		    /^[[:space:]]*alias_(database|maps) =/ || next;
			while (/(hash|btree):([^,\s]+)/g) {$a{"$1:$2"}=1;}
			END {print join(" ",keys %a),"\n";}'`; do
		[ -e ${i#*:} -a ! -e ${i#*:}.db -o ${i#*:} -nt ${i#*:}.db ] && /usr/sbin/postalias $i
	done
	# refresh other maps
	for i in `(/usr/sbin/postconf;cat $d/main.cf $d/master.cf) | perl -ne '
		    /^[[:space:]]*alias_(database|maps) =/ && next;
			/^[^#]*(hash|btree):/ || next;
			while (/(hash|btree):([^,\s]+)/g) {$a{"$1:$2"}=1;}
			END {print join(" ",keys %a),"\n";}'`; do
		[ -e ${i#*:} -a ! -e ${i#*:}.db -o ${i#*:} -nt ${i#*:}.db ] && /usr/sbin/postmap $i
	done

	/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
        echo
	return $RETVAL
}

stop() {
	echo -n "Shutting down postfix: "
	/usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
	echo
	return $RETVAL
}

reload() {
	echo -n "Reloading postfix: "
	/usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure
	RETVAL=$?
	echo
	return $RETVAL
}

abort() {
	/usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure
	return $?
}

flush() {
	/usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure
	return $?
}

check() {
	/usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure
	return $?
}

restart() {
	stop
	start
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  reload)
	reload
	;;
  abort)
	abort
	;;
  flush)
	flush
	;;
  check)
	check
	;;
  status)
  	status master
	;;
  condrestart)
	[ -f /var/lock/subsys/postfix ] && restart || :
	;;
  *)
	echo "Usage: postfix {start|stop|restart|reload|abort|flush|check|status|condrestart}"
	exit 1
esac

exit $?