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 13name="postfix" 14rcvar=$name 15postfix_command="/usr/sbin/${name}" 16required_files="/etc/${name}/main.cf" 17start_precmd="postfix_precmd" 18start_cmd="postfix_op" 19stop_cmd="postfix_op" 20reload_cmd="postfix_op" 21status_cmd="postfix_op" 22extra_commands="reload status" 23spooletcdir="/var/spool/${name}/etc" 24postconf="/usr/sbin/postconf" 25required_dirs=$spooletcdir 26 27_rebuild() { 28 echo "${name}: rebuilding ${1} ($2 ${1}.db)" 29 $($postconf -h newaliases_path) 30} 31 32postfix_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 68postfix_op() 69{ 70 ${postfix_command} ${rc_arg} 71} 72 73check_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 97load_rc_config $name 98unset _rc_d_postfix 99postfix=$(check_use_postfix) 100run_rc_command "$1" 101