aboutsummaryrefslogtreecommitdiff
path: root/mail/milter-manager/files/milter-manager.in
blob: 19ba694bf9aa2c8380b0dab7292039ccc919f066 (plain) (blame)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: milter-manager
# REQUIRE: LOGIN
# BEFORE: mail
# KEYWORD: shutdown

# Define these miltermanager_* variables in one of these files:
#	/etc/rc.conf
#	/etc/rc.conf.local
#	/etc/rc.conf.d/miltermanager
#
# miltermanager_enable (bool):    Set to "NO" by default.
#                                 Set it to "YES" to enable milter-manager
# miltermanager_cfgdir (str):     Configuration directory. see milter-manager(1)
# miltermanager_profiles (list):  Set to "" by default.
#                                 Define your profiles here.
# miltermanager_debug (str):      Run the milter in debug mode(can run one instance only).
#
# miltermanager_${profile}_* :   Variables per profile.
#
#  all parameters below now can be set in milter-manager.conf(5).
# miltermanager_uid (str):        Set username to run milter.
# miltermanager_gid (str):        Set groupname to run milter.
# miltermanager_socket_gid (str): Set groupname to access the socket.
# miltermanager_socket (str):     Path to the milter socket in socketspec.
#                                 Sockets must be different from each other.
# miltermanager_flags (str):      Flags passed to start command.

. /etc/rc.subr

name="miltermanager"
rcvar=miltermanager_enable

extra_commands="reload"
start_precmd="manager_precmd"
stop_postcmd="manager_postcmd"
command="%%PREFIX%%/sbin/milter-manager"
_piddir="/var/run/milter-manager"
pidfile="${_piddir}/pid"

load_rc_config $name

#
# DO NOT CHANGE THESE DEFAULT VALUES HERE
#
: ${miltermanager_enable="NO"}
: ${miltermanager_cfgdir="%%PREFIX%%/etc/milter-manager"}
: ${miltermanager_uid="mailnull"}
: ${miltermanager_gid="mail"}
: ${miltermanager_socket_gid="mail"}
: ${miltermanager_debug="NO"}
# Options other than above can be set with $miltermanager_flags.
# see milter-manager documentation for detail.

if [ -n "$2" ]; then
    profile="$2"
    if [ "x${miltermanager_profiles}" != "x" ]; then
	pidfile="${_piddir}/${profile}.pid"
	eval miltermanager_enable="\${miltermanager_${profile}_enable:-${miltermanager_enable}}"
	eval miltermanager_cfgdir="\${miltermanager_${profile}_cfgdir:-}"
	if [ ! -d "${miltermanager_cfgdir}" ];then
	    echo "You must set config directory for (miltermanager_${profile}_cfgdir)"
	    exit 1
	fi
	eval miltermanager_socket="\${miltermanager_${profile}_socket:-}"

	command_args="--pid-file ${pidfile}"

	if [ -d "${miltermanager_cfgdir}" ];then
	    command_args="${command_args} --config-dir=${miltermanager_cfgdir}"
	fi
	if [ -n "${miltermanager_uid}" ] ; then
	    command_args="${command_args} --user-name ${miltermanager_uid}"
	fi
	if [ -n "${miltermanager_gid}" ] ; then
	    command_args="${command_args} --group-name ${miltermanager_gid}"
	fi
	if [ -n "${miltermanager_socket_gid}" ] ; then
	    command_args="${command_args} --unix-socket-group ${miltermanager_socket_gid}"
	fi
	if [ -n "${miltermanager_socket}" ] ; then
	    command_args="${command_args} --connection-spec ${miltermanager_socket}"
	fi
	command_args="${command_args} --daemon"
    else
	echo "$0: extra argument ignored"
    fi
else
    if [ "x${miltermanager_profiles}" != "x" -a "x$1" != "x" ]; then
	if [ "x$1" != "xrestart" ]; then
	    for profile in ${miltermanager_profiles}; do
		echo "===> miltermanager profile: ${profile}"
		%%PREFIX%%/etc/rc.d/milter-manager $1 ${profile}
		retcode="$?"
		if [ "0${retcode}" -ne 0 ]; then
		    failed="${profile} (${retcode}) ${failed:-}"
		else
		    success="${profile} ${success:-}"
		fi
	    done
	    exit 0
	else
	    restart_precmd=""
	fi
    else
	command_args="--pid-file ${pidfile}"

	if [ -d "${miltermanager_cfgdir}" ];then
	    command_args="${command_args} --config-dir=${miltermanager_cfgdir}"
	fi
	if [ -n "${miltermanager_uid}" ] ; then
	    command_args="${command_args} --user-name ${miltermanager_uid}"
	fi
	if [ -n "${miltermanager_gid}" ] ; then
	    command_args="${command_args} --group-name ${miltermanager_gid}"
	fi
	if [ -n "${miltermanager_socket_gid}" ] ; then
	    command_args="${command_args} --unix-socket-group ${miltermanager_socket_gid}"
	fi
	if [ -n "${miltermanager_socket}" ] ; then
	    command_args="${command_args} --connection-spec ${miltermanager_socket}"
	fi
	if checkyesno miltermanager_debug ; then
	    command_args="${command_args} --verbose"
	else
	    command_args="${command_args} --daemon"
	fi
    fi
fi

manager_precmd ()
{
    if [ ! -d ${_piddir} ] ; then
        mkdir -p ${_piddir}
    fi
    if [ -n "${miltermanager_uid}" ] ; then
        chown ${miltermanager_uid} ${_piddir}
    fi
    if [ -n "${miltermanager_gid}" ] ; then
        chgrp ${miltermanager_gid} ${_piddir}
    fi
}

manager_postcmd ()
{
    # just if the directory is empty
    rmdir ${_piddir} > /dev/null 2>&1
}

run_rc_command "$1"