1#!/bin/sh 2### BEGIN INIT INFO 3# Provides: postfix MTA 4# Default-Start: 2345 5# Default-Stop: 016 6# Short-Description: start and stop postfix 7# Description: Postfix is a Mail Transport Agent, which is the program 8# that moves mail from one machine to another. 9### END INIT INFO 10 11success() { 12 echo " Successful" 13 exit 0 14} 15 16fail() { 17 echo " Failed" 18 exit 1 19 20} 21 22check_return () { 23 local ret="$1" 24 25 if [ "$ret" = "0" ]; then 26 success 27 else 28 fail 29 fi 30} 31 32PIDFile=/var/spool/postfix/pid/master.pid 33case "$1" in 34 35 start) 36 echo -n "Starting Postfix..." 37 if [ ! -e /etc/aliases.db ]; then 38 # The alias database is necessary for postfix to work correctly. 39 echo "Creating aliases database ..." 40 newaliases 41 fi 42 if ! postfix status >/dev/null 2>&1; then 43 /usr/sbin/check_hostname.sh 44 postfix start 45 check_return $? 46 else 47 success 48 fi 49 ;; 50 51 stop) 52 echo -n "Stopping Postfix..." 53 if postfix status >/dev/null 2>&1; then 54 postfix stop 55 check_return $? 56 else 57 success 58 fi 59 ;; 60 61 reload) 62 echo -n "Reloading Postfix..." 63 if postfix status >/dev/null 2>&1; then 64 postfix reload 65 check_return $? 66 else 67 postfix start 68 check_return $? 69 fi 70 ;; 71 72 restart) 73 $0 stop 74 sleep 1 75 $0 start 76 ;; 77 78 status) 79 if postfix status >/dev/null 2>&1; then 80 pid=`sed -e 's/\s//g' $PIDFile` 81 echo "The Postfix mail system is running (PID: $pid)" 82 exit 0 83 else 84 echo "The Postfix mail system is not running" 85 exit 1 86 fi 87 ;; 88 89 *) 90 echo "Usage: $0 {start|stop|status|reload|restart}" 91 exit 1 92 ;; 93esac 94 95