Thu Jul 23 17:12:16 2015 UTC ()
Implement "status" command for postfix - makes tools like ansible
happier.


(riz)
diff -r1.16 -r1.17 src/etc/rc.d/postfix

cvs diff -r1.16 -r1.17 src/etc/rc.d/postfix (switch to unified diff)

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