postfix revision 1.13
1#!/bin/sh
2#
3# $NetBSD: postfix,v 1.13 2006/09/07 15:26:08 christos 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"
21extra_commands="reload"
22spooletcdir="/var/spool/${name}/etc"
23postconf="/usr/sbin/postconf"
24required_dirs=$spooletcdir
25
26_rebuild() {
27	echo "${name}: rebuilding ${1} ($2 ${1}.db)"
28	$($postconf -h newaliases_path)
29}
30
31postfix_precmd()
32{
33	# As this is called after the is_running and required_dir checks
34	# are made in run_rc_command(), we can safely assume ${spooletcdir}
35	# exists and postfix isn't running at this point (unless forcestart
36	# is used).
37	#
38
39	for f in localtime resolv.conf services; do
40		if [ -f /etc/$f ]; then
41			cmp -s /etc/$f ${spooletcdir}/$f || \
42			    cp -p /etc/$f ${spooletcdir}/$f
43		fi
44	done
45
46	for f in $($postconf -h alias_database); do
47		OIFS="${IFS}"
48		IFS="${IFS}:"
49		set -- $f
50		IFS="${OIFS}"
51		case "$1" in
52		hash)
53			if [ -f "$2.db" ]; then
54				if [ ! "$2" -ot "$2.db" ]; then
55					_rebuild "$2" "out of date"
56				fi
57			else
58				_rebuild "$2" "missing"
59			fi
60			;;
61		*)
62			;;
63		esac
64	done
65}
66
67postfix_op()
68{
69	${postfix_command} ${rc_arg}
70}
71
72load_rc_config $name
73run_rc_command "$1"
74