File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,32 @@ logfile="/var/log/$prog"
36
36
export GOMAXPROCS=${GOMAXPROCS:- 2}
37
37
export MAXWAIT=${MAXWAIT:- 10}
38
38
39
+ get_port () {
40
+ # get port number from the consul config file and assign to a variable
41
+ # passed in as the first argument
42
+ #
43
+ # usage: get_port var_name
44
+ local __setvar=$1
45
+ local config_dir
46
+ local config_file
47
+ local port
48
+
49
+ config_dir=" ${CONFIG_DIR:-/ etc/ consul.d} "
50
+
51
+ if [ -d " ${config_dir} " ]; then
52
+ config_file=$( find " ${config_dir} " -name \* .json)
53
+ if [ -f " ${config_file} " ]; then
54
+ # grab port number from json file with some awk magic
55
+ port=$(
56
+ /bin/awk ' /ports/ { getline; print $2 }' " ${config_file} "
57
+ )
58
+ fi
59
+ fi
60
+
61
+ eval $__setvar =" ${port:- 8500} "
62
+ }
63
+
64
+
39
65
start () {
40
66
[ -x $exec ] || exit 5
41
67
@@ -62,9 +88,13 @@ start() {
62
88
local pid=$( < ${pidfile} )
63
89
local curwait=0
64
90
local ready=0
91
+ local consul_port
92
+
93
+ # assign $consul_port based on what the `get_port` func returns
94
+ get_port consul_port
65
95
66
96
while checkpid ${pid} && [ $curwait -lt ${MAXWAIT} ] && [ $ready -ne 1 ]; do
67
- if netstat -nptl | grep -q " ^tcp.*:8500 .*LISTEN \+${pid} \/${prog} " ; then
97
+ if netstat -nptl | grep -q " ^tcp.*:${consul_port} .*LISTEN \+${pid} \/${prog} " ; then
68
98
ready=1
69
99
else
70
100
sleep 1
Original file line number Diff line number Diff line change 1
- CMD_OPTS="agent -config-dir=/etc/consul.d -data-dir=/var/lib/consul"
1
+ CONFIG_DIR="/etc/consul.d"
2
+ DATA_DIR="/var/lib/consul"
3
+ CMD_OPTS="agent -config-dir=${CONFIG_DIR} -data-dir=${DATA_DIR}"
2
4
#GOMAXPROCS=4
You can’t perform that action at this time.
0 commit comments