summaryrefslogtreecommitdiff
path: root/mail/dkfilter/files/dkfilter_in.in
blob: 06ec480b6678f7215d43a6c3513cef63ab33705f (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
#!/bin/sh
# $FreeBSD$
#

# PROVIDE: dkfilter_in
# REQUIRE: LOGIN
# BEFORE: mail
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable dkfilter.in:
#
# dkfilter_in_enable="YES"
#

. /etc/rc.subr

name=dkfilter_in
rcvar=dkfilter_in_enable

# set defaults

: ${dkfilter_in_enable="NO"}
: ${dkfilter_in_flags="127.0.0.1:10025 127.0.0.1:10026"}
: ${dkfilter_in_pidfile="/var/run/dkfilter_in.pid"}
: ${dkfilter_in_user="dkfilter"}

start_cmd="dkfilter_in_start"
stop_cmd="dkfilter_in_stop"

dkfilter_in_start()
{
	if [ -f ${dkfilter_in_pidfile} ]; then
		echo "${name} already running?"
		exit 1
	fi
	echo "Starting ${name}."
	logger -t ${name} "Starting ${name}"
	tmpfile=`mktemp /tmp/dkfilter.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`
	touch ${dkfilter_in_pidfile}
	chown ${dkfilter_in_user} ${dkfilter_in_pidfile}
	su -m ${dkfilter_in_user} -c "daemon -p ${dkfilter_in_pidfile} \
		%%PREFIX%%/bin/dkfilter.in ${dkfilter_in_flags}" \
		> /dev/null 2> ${tmpfile}
	# wait until dkfilter start.
	while true
	do
		filesize=`ls -l $tmpfile|awk '{print $5}'`
		if [ ${filesize} -gt 0 ]; then
			break
		fi
	done

	logger -t ${name} `cat ${tmpfile}`
	err=`grep Error ${tmpfile}`
	if [ "${err}" ]; then
		echo "Failed to start ${name}."
		echo "${err}"
		rm -f ${dkfilter_in_pidfile}
	else
		# To prevent DoS attack by dkfilter_in_user.
		chown root:wheel ${dkfilter_in_pidfile}
	fi
	rm -f ${tmpfile}
}

dkfilter_in_stop()
{
	if [ ! -f ${dkfilter_in_pidfile} ]; then
		echo "${name} not running?"
		exit 1
	fi
	kill `cat ${dkfilter_in_pidfile}`
	rm -f ${dkfilter_in_pidfile}
	echo "Stopping ${name}"
}

load_rc_config $name
run_rc_command "$1"