Home | History | Annotate | Line # | Download | only in rc.d
postfix revision 1.17
      1 #!/bin/sh
      2 #
      3 # $NetBSD: postfix,v 1.17 2015/07/23 17:12:16 riz Exp $
      4 #
      5 
      6 # PROVIDE: mail
      7 # REQUIRE: LOGIN
      8 #	we make mail start late, so that things like .forward's are not
      9 #	processed until the system is fully operational
     10 
     11 $_rc_subr_loaded . /etc/rc.subr
     12 
     13 name="postfix"
     14 rcvar=$name
     15 postfix_command="/usr/sbin/${name}"
     16 required_files="/etc/${name}/main.cf"
     17 start_precmd="postfix_precmd"
     18 start_cmd="postfix_op"
     19 stop_cmd="postfix_op"
     20 reload_cmd="postfix_op"
     21 status_cmd="postfix_op"
     22 extra_commands="reload status"
     23 spooletcdir="/var/spool/${name}/etc"
     24 postconf="/usr/sbin/postconf"
     25 required_dirs=$spooletcdir
     26 
     27 _rebuild() {
     28 	echo "${name}: rebuilding ${1} ($2 ${1}.db)"
     29 	$($postconf -h newaliases_path)
     30 }
     31 
     32 postfix_precmd()
     33 {
     34 	# As this is called after the is_running and required_dir checks
     35 	# are made in run_rc_command(), we can safely assume ${spooletcdir}
     36 	# exists and postfix isn't running at this point (unless forcestart
     37 	# is used).
     38 	#
     39 
     40 	for f in localtime resolv.conf services; do
     41 		if [ -f /etc/$f ]; then
     42 			cmp -s /etc/$f ${spooletcdir}/$f || \
     43 			    cp -p /etc/$f ${spooletcdir}/$f
     44 		fi
     45 	done
     46 
     47 	for f in $($postconf -h alias_database); do
     48 		OIFS="${IFS}"
     49 		IFS="${IFS}:"
     50 		set -- $f
     51 		IFS="${OIFS}"
     52 		case "$1" in
     53 		hash)
     54 			if [ -f "$2.db" ]; then
     55 				if [ ! "$2" -ot "$2.db" ]; then
     56 					_rebuild "$2" "out of date"
     57 				fi
     58 			else
     59 				_rebuild "$2" "missing"
     60 			fi
     61 			;;
     62 		*)
     63 			;;
     64 		esac
     65 	done
     66 }
     67 
     68 postfix_op()
     69 {
     70 	${postfix_command} ${rc_arg}
     71 }
     72 
     73 check_use_postfix()
     74 {
     75 	_mta_path=$(awk '/^sendmail[ \t]/{print$2}' /etc/mailer.conf)
     76 	_postfix_path="/usr/libexec/postfix/sendmail"
     77 	_sendmail_path="/usr/libexec/sendmail/sendmail"
     78 
     79 	if [ "${postfix}" != "check" ]; then
     80 	    echo "${postfix}"
     81 	elif [ "${_mta_path}" = "${_postfix_path}" ]; then
     82 	    echo YES
     83 	else
     84 	    echo "WARNING: default postfix not used as not selected in mailer.conf" >&2
     85 	    if [ "${_mta_path}" = "${_sendmail_path}" -a \
     86 		! -x "${_mta_path}" ]; then
     87 		echo "WARNING: mailer.conf points to the removed sendmail" >&2
     88 		echo "update /etc/mailer.conf to get a working mailer configuration" >&2
     89 	    fi
     90 	    echo NO
     91 	fi
     92 }
     93 
     94 # force re-evaluation of /etc/rc.conf and resetting of $sendmail
     95 _rc_conf_loaded=false
     96 _rc_d_postfix=check
     97 load_rc_config $name
     98 unset _rc_d_postfix
     99 postfix=$(check_use_postfix)
    100 run_rc_command "$1"
    101