Lines 6-52
Link Here
|
6 |
# REQUIRE: LOGIN |
6 |
# REQUIRE: LOGIN |
7 |
# KEYWORD: shutdown |
7 |
# KEYWORD: shutdown |
8 |
# |
8 |
# |
9 |
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf |
9 |
# Add consul_enable="YES" to /etc/rc.conf to enable Consul |
10 |
# to enable this service: |
|
|
11 |
# |
10 |
# |
12 |
# consul_enable (bool): Set to NO by default. |
11 |
# Additional variables you can define are: |
13 |
# Set it to YES to enable consul. |
12 |
# |
14 |
# consul_user (user): Set user to run consul. |
13 |
# consul_debug: Set it to YES to enable Consul debugging to syslog |
15 |
# Default is "consul". |
14 |
# Default: NO |
16 |
# consul_group (group): Set group to run consul. |
15 |
# consul_user: Username to run Consul |
17 |
# Default is "consul". |
16 |
# Default: %%CONSUL_USER%% |
18 |
# consul_dir (dir): Set dir to run consul in. |
17 |
# consul_datadir: Directory for the agent to store state |
19 |
# Default is "/var/db/consul". |
18 |
# Default: %%CONSUL_DATADIR%% |
|
|
19 |
# consul_pidfile: Full path of the Consul PID file |
20 |
# Default: /var/run/consul.pid |
21 |
# consul_env: Set environment variables used with Consul |
22 |
# Default: |
23 |
# consul_args: Additional command-line options |
24 |
# Default: |
20 |
|
25 |
|
21 |
. /etc/rc.subr |
26 |
. /etc/rc.subr |
22 |
|
27 |
|
23 |
name=consul |
28 |
name=consul |
24 |
rcvar=consul_enable |
29 |
rcvar=consul_enable |
|
|
30 |
|
31 |
restart_precmd="consul_checkconfig" |
32 |
reload_precmd="consul_checkconfig" |
33 |
configtest_cmd="consul_checkconfig" |
25 |
extra_commands="reload configtest" |
34 |
extra_commands="reload configtest" |
26 |
|
35 |
|
27 |
load_rc_config $name |
36 |
load_rc_config $name |
28 |
|
37 |
|
29 |
: ${consul_enable:="NO"} |
38 |
: ${consul_enable:=NO} |
30 |
: ${consul_user:="consul"} |
39 |
: ${consul_user:=%%CONSUL_USER%%} |
31 |
: ${consul_group:="consul"} |
40 |
: ${consul_datadir:=%%CONSUL_DATADIR%%} |
32 |
: ${consul_dir:="/var/db/consul"} |
41 |
: ${consul_pidfile:=/var/run/consul.pid} |
33 |
|
42 |
|
34 |
pidfile=/var/run/consul.pid |
43 |
if checkyesno consul_debug; then |
|
|
44 |
consul_syslog_flags="-T ${name}" |
45 |
fi |
46 |
|
47 |
pidfile=${consul_pidfile} |
48 |
required_dirs="%%ETCDIR%% ${consul_datadir}" |
49 |
|
35 |
procname="%%PREFIX%%/bin/consul" |
50 |
procname="%%PREFIX%%/bin/consul" |
36 |
command="/usr/sbin/daemon" |
51 |
command="/usr/sbin/daemon" |
37 |
command_args="-f -p ${pidfile} /usr/bin/env ${consul_env} ${procname} agent -data-dir=${consul_dir} -config-dir=%%PREFIX%%/etc/consul.d ${consul_args}" |
52 |
command_consul="/usr/bin/env ${consul_env} ${procname} agent -data-dir=${consul_datadir} -config-dir=%%ETCDIR%% ${consul_args}" |
|
|
53 |
command_args="-f ${consul_syslog_flags} -p ${pidfile} -u ${consul_user} -t ${name} ${command_consul}" |
54 |
unset consul_user |
38 |
|
55 |
|
39 |
start_precmd=consul_startprecmd |
56 |
consul_checkconfig() |
40 |
|
|
|
41 |
consul_startprecmd() |
42 |
{ |
57 |
{ |
43 |
if [ ! -e ${pidfile} ]; then |
58 |
echo "Performing sanity check on ${name} configuration:" |
44 |
install -o ${consul_user} -g ${consul_group} /dev/null ${pidfile}; |
59 |
eval ${procname} validate %%ETCDIR%% |
45 |
fi |
|
|
46 |
|
47 |
if [ ! -d ${consul_dir} ]; then |
48 |
install -d -o ${consul_user} -g ${consul_group} ${consul_dir} |
49 |
fi |
50 |
} |
60 |
} |
51 |
|
61 |
|
52 |
run_rc_command "$1" |
62 |
run_rc_command "$1" |