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