blob: b49a7a2dba2a6f5aacb2dce0403db77ec0ff42aa (
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
|
#!/bin/sh
# $FreeBSD$
#
# PROVIDE: dkimproxy_out
# REQUIRE: LOGIN
# BEFORE: mail
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable dkimproxy.out:
#
# dkimproxy_out_enable="YES"
#
# Before you enable dkimproxy.out, you also need to make your domainkey to
# set it to DNS and configurate dkimproxy_out_flags.
#
. /etc/rc.subr
name="dkimproxy_out"
rcvar=`set_rcvar`
# set defaults
: ${dkimproxy_out_enable="NO"}
: ${dkimproxy_out_flags="--conf_file=/usr/local/etc/dkimproxy_out.conf"}
: ${dkimproxy_out_pidfile="/var/run/dkimproxy_out.pid"}
: ${dkimproxy_out_user="dkimproxy"}
start_cmd="dkimproxy_out_start"
stop_cmd="dkimproxy_out_stop"
dkimproxy_out_start()
{
if [ -f ${dkimproxy_out_pidfile} ]; then
echo "${name} already running?"
exit 1
fi
if pw user show "${dkimproxy_out_user}" > /dev/null 2>&1; then else
echo "dkimproxy_out_user: ${dkimproxy_out_user} not found"
exit 1
fi
echo "Starting ${name}"
logger -t ${name} "Starting ${name}"
touch ${dkimproxy_out_pidfile}
chown ${dkimproxy_out_user} ${dkimproxy_out_pidfile}
tmpfile=`mktemp /tmp/${name}.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`
su -m ${dkimproxy_out_user} -c "daemon -c -p ${dkimproxy_out_pidfile} \
%%PREFIX%%/bin/dkimproxy.out ${dkimproxy_out_flags}" \
> /dev/null 2> ${tmpfile}
# wait until dkimproxy 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 ${dkimproxy_out_pidfile}
else
# To prevent DoS attack by dkimproxy_out_user.
chown root:wheel ${dkimproxy_out_pidfile}
fi
rm -f ${tmpfile}
}
dkimproxy_out_stop()
{
if [ ! -f ${dkimproxy_out_pidfile} ]; then
echo "${name} not running?"
exit 1
fi
echo "Stopping ${name}"
logger -t ${name} "Stopping ${name}"
kill `cat ${dkimproxy_out_pidfile}`
rm -f ${dkimproxy_out_pidfile}
}
load_rc_config $name
run_rc_command "$1"
|