Skip to content

Commit 716c550

Browse files
amuraruJin Huang
andcommitted
Use getent instead of nslookup for starting scripts (#5)
Co-authored-by: Jin Huang <[email protected]>
1 parent 1b7efd7 commit 716c550

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

docker/bin/zookeeperFunctions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ function zkConfig() {
1919
function zkConnectionString() {
2020
# If the client service address is not yet available, then return localhost
2121
set +e
22-
nslookup "${CLIENT_HOST}" 2>/dev/null 1>/dev/null
23-
if [[ $? -eq 1 ]]; then
22+
getent hosts "${CLIENT_HOST}" 2>/dev/null 1>/dev/null
23+
if [[ $? -ne 0 ]]; then
2424
set -e
2525
echo "localhost:${CLIENT_PORT}"
2626
else

docker/bin/zookeeperReady.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ OK=$(echo ruok | nc 127.0.0.1 $CLIENT_PORT)
2525
# Check to see if zookeeper service answers
2626
if [[ "$OK" == "imok" ]]; then
2727
set +e
28-
nslookup $DOMAIN
29-
if [[ $? -eq 1 ]]; then
28+
getent hosts $DOMAIN
29+
if [[ $? -ne 0 ]]; then
3030
set -e
3131
echo "There is no active ensemble, skipping readiness probe..."
3232
exit 0

docker/bin/zookeeperStart.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,27 @@ if [[ -n "$ENVOY_SIDECAR_STATUS" ]]; then
6969
fi
7070
set -e
7171

72-
# Determine if there is a ensemble available to join by checking the service domain
72+
# Determine if there is an ensemble available to join by checking the service domain
7373
set +e
74-
nslookup $DOMAIN
75-
if [[ $? -eq 0 ]]; then
76-
ACTIVE_ENSEMBLE=true
77-
elif nslookup $DOMAIN | grep -q "server can't find $DOMAIN"; then
78-
echo "there is no active ensemble"
79-
ACTIVE_ENSEMBLE=false
80-
else
81-
# If an nslookup of the headless service domain fails, then there is no
82-
# active ensemble yet, but in certain cases nslookup of headless service
74+
getent hosts $DOMAIN # This only performs a dns lookup
75+
if [[ $? -ne 0 ]]; then
76+
# If dns lookup of the headless service domain fails, then there is no
77+
# active ensemble yet, but in certain cases the dns lookup of headless service
8378
# takes a while to come up even if there is active ensemble
8479
ACTIVE_ENSEMBLE=false
8580
declare -i count=20
8681
while [[ $count -ge 0 ]]
8782
do
8883
sleep 2
8984
((count=count-1))
90-
nslookup $DOMAIN
85+
getent hosts $DOMAIN
9186
if [[ $? -eq 0 ]]; then
9287
ACTIVE_ENSEMBLE=true
9388
break
9489
fi
9590
done
91+
else
92+
ACTIVE_ENSEMBLE=true
9693
fi
9794

9895
if [[ "$ONDISK_MYID_CONFIG" == true && "$ONDISK_DYN_CONFIG" == true ]]; then

0 commit comments

Comments
 (0)