[BACK]Return to postfix CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / etc / rc.d

File: [cvs.NetBSD.org] / src / etc / rc.d / postfix (download)

Revision 1.18, Sun Oct 30 15:47:06 2016 UTC (2 years, 4 months ago) by riastradh
Branch: MAIN
CVS Tags: prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-8-base, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, matt-nb8-mediatek-base, matt-nb8-mediatek, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, HEAD
Changes since 1.17: +5 -4 lines

Handle variable expansion and comma/space separators in postconf.

From Timo Buhrmester:
https://mail-index.netbsd.org/tech-userlevel/2016/08/20/msg010301.html

#!/bin/sh
#
# $NetBSD: postfix,v 1.18 2016/10/30 15:47:06 riastradh Exp $
#

# PROVIDE: mail
# REQUIRE: LOGIN
#	we make mail start late, so that things like .forward's are not
#	processed until the system is fully operational

$_rc_subr_loaded . /etc/rc.subr

name="postfix"
rcvar=$name
postfix_command="/usr/sbin/${name}"
required_files="/etc/${name}/main.cf"
start_precmd="postfix_precmd"
start_cmd="postfix_op"
stop_cmd="postfix_op"
reload_cmd="postfix_op"
status_cmd="postfix_op"
extra_commands="reload status"
spooletcdir="/var/spool/${name}/etc"
postconf="/usr/sbin/postconf"
required_dirs=$spooletcdir

_rebuild() {
	echo "${name}: rebuilding ${1} ($2 ${1}.db)"
	$($postconf -h newaliases_path)
}

postfix_precmd()
{
	# As this is called after the is_running and required_dir checks
	# are made in run_rc_command(), we can safely assume ${spooletcdir}
	# exists and postfix isn't running at this point (unless forcestart
	# is used).
	#

	for f in localtime resolv.conf services; do
		if [ -f /etc/$f ]; then
			cmp -s /etc/$f ${spooletcdir}/$f || \
			    cp -p /etc/$f ${spooletcdir}/$f
		fi
	done

	OIFS="${IFS}"
	IFS="${IFS},"
	for f in $($postconf -hx alias_database); do
		IFS="${OIFS}:"
		set -- $f
		IFS="${OIFS}"
		case "$1" in
		hash)
			if [ -f "$2.db" ]; then
				if [ ! "$2" -ot "$2.db" ]; then
					_rebuild "$2" "out of date"
				fi
			else
				_rebuild "$2" "missing"
			fi
			;;
		*)
			;;
		esac
	done
}

postfix_op()
{
	${postfix_command} ${rc_arg}
}

check_use_postfix()
{
	_mta_path=$(awk '/^sendmail[ \t]/{print$2}' /etc/mailer.conf)
	_postfix_path="/usr/libexec/postfix/sendmail"
	_sendmail_path="/usr/libexec/sendmail/sendmail"

	if [ "${postfix}" != "check" ]; then
	    echo "${postfix}"
	elif [ "${_mta_path}" = "${_postfix_path}" ]; then
	    echo YES
	else
	    echo "WARNING: default postfix not used as not selected in mailer.conf" >&2
	    if [ "${_mta_path}" = "${_sendmail_path}" -a \
		! -x "${_mta_path}" ]; then
		echo "WARNING: mailer.conf points to the removed sendmail" >&2
		echo "update /etc/mailer.conf to get a working mailer configuration" >&2
	    fi
	    echo NO
	fi
}

# force re-evaluation of /etc/rc.conf and resetting of $sendmail
_rc_conf_loaded=false
_rc_d_postfix=check
load_rc_config $name
unset _rc_d_postfix
postfix=$(check_use_postfix)
run_rc_command "$1"