aboutsummaryrefslogtreecommitdiffstats
path: root/main/postgrey/postgrey.initd
blob: c9e51ceba9d173cc775839b899fa47a7ed55eca0 (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
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
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/www/viewcvs.gentoo.org/raw_cvs/gentoo-x86/mail-filter/postgrey/files/postgrey.rc.new,v 1.10 2008/05/21 18:45:44 dertobi123 Exp $

conf="/etc/conf.d/postgrey"

opts="${opts} reload"

depend() {
	need net
	after firewall
	before postfix
	provide postfix_greylist
}

conf_error() {
	eerror "You need to setup ${conf} first"
	return 1
}

checkconfig() {
if [ -z "${POSTGREY_TYPE}" ]
	then
		einfo "You need to choose the server type you want"
		einfo "by setting the POSTGREY_TYPE variable in ${conf}."
	else
	if [ "x${POSTGREY_TYPE}" = "xinet" ]
		then
			if [ -z "${POSTGREY_PORT}" ] || [ -z "${POSTGREY_HOST}" ]
				then
					einfo "The following entries are missing in ${conf}:"
					[ -z "${POSTGREY_HOST}" ] && einfo "  - POSTGREY_HOST"
					[ -z "${POSTGREY_PORT}" ] && einfo "  - POSTGREY_PORT"
					conf_error
			fi
			POSTGREY_ADDR="${POSTGREY_TYPE}=${POSTGREY_HOST}:${POSTGREY_PORT}"
		else
			if [ -z "${POSTGREY_SOCKET}" ]
			then
				einfo "The following entries are missing in ${conf}:"
				[ -z "${POSTGREY_SOCKET}" ] && einfo "  - POSTGREY_SOCKET"
				conf_error
			fi
			POSTGREY_ADDR="${POSTGREY_TYPE}=${POSTGREY_SOCKET}"
	fi
fi

	if [ -z "${POSTGREY_PID}" ]
		then
		einfo "The following entries are missing in ${conf}:"
		[ -z "${POSTGREY_PID}" ] && einfo "  - POSTGREY_PID"
		conf_error
	fi
}

start() {
	checkconfig || return 1
	ebegin "Starting Postgrey"
	
	# HACK -- start a subshell and corrects perms on the socket...
	( if [ "x${POSTGREY_TYPE}" = "xunix" ]; then
	rm -f ${POSTGREY_SOCKET};
	while ! test -S ${POSTGREY_SOCKET}; do sleep 1; done;
	chmod a+rw,a-x ${POSTGREY_SOCKET}; fi ) &

	if [ -z ${POSTGREY_DELAY} ] ; then
		POSTGREY_DELAY_ARG=""
	else
		POSTGREY_DELAY_ARG="--delay=${POSTGREY_DELAY}"
	fi

	if [ -z "${POSTGREY_TEXT}" ] ; then
		POSTGREY_TEXT_ARG=""
	else
		POSTGREY_TEXT_ARG="--greylist-text=${POSTGREY_TEXT}"
	fi

	start-stop-daemon --start --quiet --background \
		--pidfile=${POSTGREY_PID} \
		--name postgrey \
		--exec /usr/sbin/postgrey -- \
		--${POSTGREY_ADDR} \
		--daemonize \
		--pidfile=${POSTGREY_PID} \
		${POSTGREY_DELAY_ARG} \
		${POSTGREY_OPTS} \
		"${POSTGREY_TEXT_ARG}"
	eend ${?}
}

stop() {
	ebegin "Stopping Postgrey"
	start-stop-daemon --stop --quiet --pidfile ${POSTGREY_PID}
	eend ${?}
}

reload() {
	ebegin "Reloading Postgrey"
	start-stop-daemon --stop --signal HUP --oknodo --pidfile ${POSTGREY_PID}
	eend $?
}