summaryrefslogtreecommitdiff
path: root/mail/postfix/files/postfix.sh
blob: 6daf21c2375ec8f11e1860ac811d057e8758e2f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!@RCD_SCRIPTS_SHELL@
#
# $NetBSD: postfix.sh,v 1.4 2004/07/19 22:02:15 jlam 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

. /etc/rc.subr

name="postfix"
rcvar=$name
postfix_command="@PREFIX@/sbin/${name}"
: ${required_files=`@PREFIX@/sbin/postconf -h config_directory`/main.cf}
start_precmd="postfix_precmd"
start_cmd="postfix_op"
stop_cmd="postfix_op"
reload_cmd="postfix_op"
extra_commands="reload"
: ${spooletcdir=`@PREFIX@/sbin/postconf -h queue_directory`/etc}
required_dirs=$spooletcdir

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
}

postfix_op()
{
	case ${rc_arg} in
	start)
		for _f in $required_dirs; do
			if [ ! -d "${_f}/." ]; then
				warn "${_f} is not a directory."
				if [ -z $rc_force ]; then
					return 1
				fi
			fi
		done
		for _f in $required_files; do
			if [ ! -r "${_f}" ]; then
				warn "${_f} is not readable."
				if [ -z $rc_force ]; then
					return 1
				fi
			fi
		done
		${postfix_command} ${rc_arg}
		;;
	*)
		${postfix_command} ${rc_arg}
		;;
	esac
}

load_rc_config $name
run_rc_command "$1"