PageRenderTime 56ms CodeModel.GetById 43ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/rc6.d/K20postfix

http://github.com/brinkman83/bashrc
Shell | 168 lines | 120 code | 23 blank | 25 comment | 27 complexity | e47d7ef0cbd2e212324812d74c409d77 MD5 | raw file
  1#!/bin/sh -e
  2
  3# Start or stop Postfix
  4#
  5# LaMont Jones <lamont@debian.org>
  6# based on sendmail's init.d script
  7
  8### BEGIN INIT INFO
  9# Provides:          postfix mail-transport-agent
 10# Required-Start:    $local_fs $remote_fs $syslog $named $network $time
 11# Required-Stop:     $local_fs $remote_fs $syslog $named $network
 12# Should-Start:      postgresql mysql clamav-daemon postgrey spamassassin
 13# Should-Stop:       postgresql mysql clamav-daemon postgrey spamassassin
 14# Default-Start:     2 3 4 5
 15# Default-Stop:      0 1 6
 16# Short-Description: start and stop the Postfix Mail Transport Agent
 17# Description:       postfix is a Mail Transport agent
 18### END INIT INFO
 19
 20PATH=/bin:/usr/bin:/sbin:/usr/sbin
 21DAEMON=/usr/sbin/postfix
 22NAME=Postfix
 23TZ=
 24unset TZ
 25
 26# Defaults - don't touch, edit /etc/default/postfix
 27SYNC_CHROOT="y"
 28
 29test -f /etc/default/postfix && . /etc/default/postfix
 30
 31test -x $DAEMON && test -f /etc/postfix/main.cf || exit 0
 32
 33. /lib/lsb/init-functions
 34#DISTRO=$(lsb_release -is 2>/dev/null || echo Debian)
 35
 36running() {
 37    queue=$(postconf -h queue_directory 2>/dev/null || echo /var/spool/postfix)
 38    if [ -f ${queue}/pid/master.pid ]; then
 39	pid=$(sed 's/ //g' ${queue}/pid/master.pid)
 40	# what directory does the executable live in.  stupid prelink systems.
 41	dir=$(ls -l /proc/$pid/exe 2>/dev/null | sed 's/.* -> //; s/\/[^\/]*$//')
 42	if [ "X$dir" = "X/usr/lib/postfix" ]; then
 43	    echo y
 44	fi
 45    fi
 46}
 47
 48case "$1" in
 49    start)
 50	log_daemon_msg "Starting Postfix Mail Transport Agent" postfix
 51	RUNNING=$(running)
 52	if [ -n "$RUNNING" ]; then
 53	    log_end_msg 0
 54	else
 55	    # if you set myorigin to 'ubuntu.com' or 'debian.org', it's wrong, and annoys the admins of
 56	    # those domains.  See also sender_canonical_maps.
 57
 58	    MYORIGIN=$(postconf -h myorigin | tr 'A-Z' 'a-z')
 59	    if [ "X${MYORIGIN#/}" != "X${MYORIGIN}" ]; then
 60		MYORIGIN=$(tr 'A-Z' 'a-z' < $MYORIGIN)
 61	    fi
 62	    if [ "X$MYORIGIN" = Xubuntu.com ] || [ "X$MYORIGIN" = Xdebian.org ]; then
 63		log_failure_msg "Invalid \$myorigin ($MYORIGIN), refusing to start"
 64		log_end_msg 1
 65		exit 1
 66	    fi
 67
 68	    # see if anything is running chrooted.
 69	    NEED_CHROOT=$(awk '/^[0-9a-z]/ && ($5 ~ "[-yY]") { print "y"; exit}' /etc/postfix/master.cf)
 70
 71	    if [ -n "$NEED_CHROOT" ] && [ -n "$SYNC_CHROOT" ]; then
 72		# Make sure that the chroot environment is set up correctly.
 73		oldumask=$(umask)
 74		umask 022
 75		cd $(postconf -h queue_directory)
 76
 77		# if we're using tls, then we need to add etc/ssl/certs/ca-certificates.crt.
 78		smtp_use_tls=$(postconf -h smtp_use_tls)
 79		smtpd_use_tls=$(postconf -h smtpd_use_tls)
 80		if [ "X$smtp_use_tls" = "Xyes" -o "X$smtpd_use_tls" = "Xyes" ]; then
 81		    if [ -f "/etc/ssl/certs/ca-certificates.crt" ]; then 
 82			mkdir -p etc/ssl/certs
 83			cp /etc/ssl/certs/ca-certificates.crt etc/ssl/certs/
 84		    fi
 85		fi
 86
 87		# if we're using unix:passwd.byname, then we need to add etc/passwd.
 88		local_maps=$(postconf -h local_recipient_maps)
 89		if [ "X$local_maps" != "X${local_maps#*unix:passwd.byname}" ]; then
 90		    if [ "X$local_maps" = "X${local_maps#*proxy:unix:passwd.byname}" ]; then
 91			sed 's/^\([^:]*\):[^:]*/\1:x/' /etc/passwd > etc/passwd
 92			chmod a+r etc/passwd
 93		    fi
 94		fi
 95
 96		FILES="etc/localtime etc/services etc/resolv.conf etc/hosts \
 97		    etc/nsswitch.conf etc/nss_mdns.config"
 98		for file in $FILES; do 
 99		    [ -d ${file%/*} ] || mkdir -p ${file%/*}
100		    if [ -f /${file} ]; then rm -f ${file} && cp /${file} ${file}; fi
101		    if [ -f  ${file} ]; then chmod a+rX ${file}; fi
102		done
103		rm -f usr/lib/zoneinfo/localtime
104		mkdir -p usr/lib/zoneinfo
105		ln -sf /etc/localtime usr/lib/zoneinfo/localtime
106		rm -f lib/libnss_*so*
107		tar cf - /lib/libnss_*so* 2>/dev/null |tar xf -
108		umask $oldumask
109	    fi
110
111	    if start-stop-daemon --start --exec ${DAEMON} -- quiet-quick-start; then
112		log_end_msg 0
113	    else
114		log_end_msg 1
115	    fi
116	fi
117    ;;
118
119    stop)
120	RUNNING=$(running)
121	log_daemon_msg "Stopping Postfix Mail Transport Agent" postfix
122	if [ -n "$RUNNING" ]; then
123	    if ${DAEMON} quiet-stop; then
124		log_end_msg 0
125	    else
126		log_end_msg 1
127	    fi
128	else
129	    log_end_msg 0
130	fi
131    ;;
132
133    restart)
134        $0 stop
135        $0 start
136    ;;
137    
138    force-reload|reload)
139	log_action_begin_msg "Reloading Postfix configuration"
140	if ${DAEMON} quiet-reload; then
141	    log_action_end_msg 0
142	else
143	    log_action_end_msg 1
144	fi
145    ;;
146
147    status)
148	RUNNING=$(running)
149	if [ -n "$RUNNING" ]; then
150	   log_success_msg "postfix is running"
151	   exit 0
152	else
153	   log_success_msg "postfix is not running"
154	   exit 3
155	fi
156    ;;
157
158    flush|check|abort)
159	${DAEMON} $1
160    ;;
161
162    *)
163	log_action_msg "Usage: /etc/init.d/postfix {start|stop|restart|reload|flush|check|abort|force-reload}"
164	exit 1
165    ;;
166esac
167
168exit 0