blob: 0cc7dfa58076609e5d43703042deb8ee6cbb771d (
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
|
# $OpenBSD: rc.subr,v 1.24 2011/03/09 19:37:16 ajacoutot Exp $
rc_err() {
echo $1
exit 1
}
rc_start() {
${rcexec} "${daemon} ${daemon_flags} ${_bg}"
}
rc_check() {
pgrep -f "^${pexp}"
}
rc_reload() {
pkill -HUP -f "^${pexp}"
}
rc_stop() {
pkill -f "^${pexp}"
}
rc_cmd() {
[ `id -u` -eq 0 -o X"$1" = "Xcheck" ] || \
rc_err "$0: need root privileges"
eval _enotsup=\${rc_${1}}
[ X"${_enotsup}" != X"NO" ] || rc_err "$0: $1 is not supported"
[ X"${rc_bg}" = X"YES" ] && local _bg="&"
case "$1" in
check)
rc_check >/dev/null
;;
start)
if ! rc_check; then
type rc_pre >/dev/null && rc_pre
rc_start >/dev/null
fi
;;
stop)
rc_stop >/dev/null
i=0
while [ $i -lt 5 ]; do
rc_check || break
sleep 1
i=$((i+1))
done
type rc_post >/dev/null && rc_post || return 0
;;
reload)
(rc_check && rc_reload) >/dev/null
;;
restart)
/etc/rc.d/${_name} stop && /etc/rc.d/${_name} start
;;
*)
rc_err "usage: $0 {start|check|reload|restart|stop}"
esac
}
[ -z "${local_rcconf}" ] && . /etc/rc.conf
[ -n "${daemon}" ] || rc_err "$0: daemon is not set"
_name=`basename $0`
eval _rcflags=\${${_name}_flags}
eval _rcuser=\${${_name}_user}
getcap -f /etc/login.conf ${_name} 1>/dev/null 2>&1 && \
daemon_class=${_name}
[ -z "${daemon_class}" ] && daemon_class=daemon
[ -z "${daemon_user}" ] && daemon_user=root
[ -n "${_rcflags}" ] && daemon_flags=${_rcflags}
[ -n "${_rcuser}" ] && daemon_user=${_rcuser}
daemon_flags=`echo ${daemon_flags} | tr -s "[:space:]"`
pexp="${daemon}${daemon_flags:+ ${daemon_flags}}"
rcexec="su -l -c ${daemon_class} -s /bin/sh ${daemon_user} -c"
|