Lines 4-35
Link Here
|
4 |
# REQUIRE: LOGIN |
4 |
# REQUIRE: LOGIN |
5 |
# KEYWORD: shutdown |
5 |
# KEYWORD: shutdown |
6 |
# |
6 |
# |
7 |
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf |
7 |
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf to enable this |
8 |
# to enable this service: |
8 |
# service: |
9 |
# |
9 |
# |
10 |
# zrepl_enable (bool): Set to YES to enable the zrepl service. |
10 |
# zrepl_enable (bool): Set to YES to enable the zrepl service. |
11 |
# Default: NO |
11 |
# Default: NO |
12 |
# zrepl_config (str): File containing zrepl configuration details. |
12 |
# zrepl_config (str): File containing zrepl configuration details. |
13 |
# Default: %%PREFIX%%/etc/zrepl/zrepl.yml |
13 |
# Default: %%PREFIX%%/etc/zrepl/zrepl.yml |
14 |
# zrepl_user (str): The user account used to run the zrepl daemon. |
14 |
# zrepl_user (str): The user account used to run the zrepl daemon. |
15 |
# Do not specifically set this to an empty string as this |
15 |
# Do not specifically set this to an empty string as this |
16 |
# will cause the daemon to run as root. |
16 |
# will cause the daemon to run as root. |
17 |
# Default: root |
17 |
# Default: root |
18 |
# zrepl_group (str): The group account used to run the zrepl daemon. |
18 |
# zrepl_group (str): The group account used to run the zrepl daemon. |
19 |
# Do not specifically set this to an empty string as this |
19 |
# Do not specifically set this to an empty string as this |
20 |
# will cause the daemon to run with group wheel. |
20 |
# will cause the daemon to run with group wheel. |
21 |
# Default: wheel |
21 |
# Default: wheel |
22 |
# zrepl_flags (str): Extra flags passed to zrepl |
22 |
# zrepl_flags (str): Extra flags passed to zrepl |
23 |
# Default: "" |
23 |
# Default: "" |
24 |
# zrepl_facility (str): Syslog facility to use |
24 |
# zrepl_facility (str): Syslog facility to use |
25 |
# Default: local0 |
25 |
# Default: local0 |
26 |
# zrepl_priority (str): Syslog priority to use |
26 |
# zrepl_priority (str): Syslog priority to use |
27 |
# Default: alert |
27 |
# Default: alert |
|
|
28 |
# |
29 |
# zrepl_gracefully (bool): Set to YES to always stop the zrepl service |
30 |
# gracefully. |
31 |
# Default: NO |
28 |
|
32 |
|
29 |
. /etc/rc.subr |
33 |
. /etc/rc.subr |
30 |
name=zrepl |
34 |
|
31 |
rcvar=${name}_enable |
35 |
name="zrepl" |
32 |
load_rc_config $name |
36 |
rcvar="${name}_enable" |
|
|
37 |
load_rc_config "$name" |
33 |
|
38 |
|
34 |
: ${zrepl_enable:="NO"} |
39 |
: ${zrepl_enable:="NO"} |
35 |
: ${zrepl_config:="%%PREFIX%%/etc/zrepl/zrepl.yml"} |
40 |
: ${zrepl_config:="%%PREFIX%%/etc/zrepl/zrepl.yml"} |
Lines 38-80
load_rc_config $name
Link Here
|
38 |
: ${zrepl_flags:=""} |
43 |
: ${zrepl_flags:=""} |
39 |
: ${zrepl_facility:="local0"} |
44 |
: ${zrepl_facility:="local0"} |
40 |
: ${zrepl_priority:="alert"} |
45 |
: ${zrepl_priority:="alert"} |
41 |
: ${zrepl_options:="${zrepl_flags} --config ${zrepl_config}"} |
46 |
: ${zrepl_options:="$zrepl_flags --config $zrepl_config"} |
|
|
47 |
: ${zrepl_gracefully:="NO"} |
48 |
|
49 |
: ${zrepl_control_group:="$zrepl_group"} |
50 |
: ${zrepl_control_mode:="0700"} |
42 |
|
51 |
|
43 |
pidfile="/var/run/zrepl.pid" |
52 |
pidfile="/var/run/zrepl.pid" |
44 |
command="/usr/sbin/daemon" |
53 |
command="/usr/sbin/daemon" |
45 |
procname="%%PREFIX%%/bin/zrepl" |
54 |
procname="%%PREFIX%%/bin/zrepl" |
46 |
command_args="-p ${pidfile} -S -l ${zrepl_facility} -s ${zrepl_priority} -T ${name} \ |
55 |
command_args="-p $pidfile -S -l $zrepl_facility -s $zrepl_priority -T $name \ |
47 |
${procname} ${zrepl_options} daemon" |
56 |
$procname $zrepl_options daemon" |
48 |
|
57 |
|
49 |
start_precmd="zrepl_precmd" |
58 |
start_precmd="zrepl_precmd" |
50 |
stop_postcmd="zrepl_postcmd" |
|
|
51 |
restart_precmd="zrepl_checkconfig" |
59 |
restart_precmd="zrepl_checkconfig" |
52 |
configtest_cmd="zrepl_checkconfig" |
60 |
configtest_cmd="zrepl_checkconfig" |
53 |
extra_commands="configtest" |
61 |
graceful_cmd="zrepl_graceful" |
54 |
|
62 |
gracefulstop_cmd="zrepl_gracefulstop" |
55 |
zrepl_precmd() |
63 |
extra_commands="configtest graceful gracefulstop" |
56 |
{ |
|
|
57 |
if [ ! -d "/var/run/zrepl/stdinserver" ]; then |
58 |
install -d -g ${zrepl_group} -o ${zrepl_user} -m 0700 -- "/var/run/zrepl"; |
59 |
install -d -g ${zrepl_group} -o ${zrepl_user} -m 0700 -- "/var/run/zrepl/stdinserver"; |
60 |
fi |
61 |
|
64 |
|
62 |
if [ ! -e "${pidfile}" ]; then |
65 |
zrepl_checkconfig() { |
63 |
install -g ${zrepl_group} -o ${zrepl_user} -- /dev/null "${pidfile}"; |
66 |
echo "Performing sanity check on zrepl configuration:" |
64 |
fi |
67 |
eval "$procname" $zrepl_options configcheck |
|
|
68 |
} |
65 |
|
69 |
|
66 |
zrepl_checkconfig |
70 |
zrepl_precmd() { |
|
|
71 |
if [ ! -d "/var/run/zrepl/stdinserver" ]; then |
72 |
install -d -g "$zrepl_control_group" -o "$zrepl_user" \ |
73 |
-m "$zrepl_control_mode" "/var/run/zrepl" |
74 |
install -d -g "$zrepl_control_group" -o "$zrepl_user" \ |
75 |
-m "$zrepl_control_mode" "/var/run/zrepl/stdinserver" |
76 |
fi |
77 |
zrepl_checkconfig |
67 |
} |
78 |
} |
68 |
|
79 |
|
69 |
zrepl_postcmd() |
80 |
zrepl_graceful() { |
70 |
{ |
81 |
local _rc_prefix _return |
71 |
rm -f -- "${pidfile}" |
82 |
( run_rc_command gracefulstop $rc_extra_args ) |
|
|
83 |
( run_rc_command start $rc_extra_args ) |
84 |
_return=$? |
85 |
[ $_return -ne 0 ] && [ -z "$rc_force" ] && return 1 |
86 |
return $_return |
72 |
} |
87 |
} |
73 |
|
88 |
|
74 |
zrepl_checkconfig() |
89 |
zrepl_gracefulstop() { |
75 |
{ |
90 |
if [ -z "$rc_pid" ]; then |
76 |
echo "Performing sanity check on zrepl configuration:" |
91 |
echo 1>&2 "${name} not running? (check $pidfile)." |
77 |
eval ${procname} ${zrepl_options} configcheck |
92 |
return 1 |
|
|
93 |
fi |
94 |
|
95 |
echo "Gracefully stopping ${name}." |
96 |
eval "$procname" signal shutdown |
97 |
wait_for_pids "$rc_pid" |
78 |
} |
98 |
} |
79 |
|
99 |
|
|
|
100 |
if checkyesno zrepl_gracefully; then |
101 |
stop_cmd="zrepl_gracefulstop" |
102 |
fi |
103 |
|
80 |
run_rc_command "$1" |
104 |
run_rc_command "$1" |