Skip to content

Commit b9a581c

Browse files
committed
feat(ns-plug): infinite connection loop
Make sure that ns-plug always try to connect to the controller. This fix will allow automatica re-connection in case of disaster recovery of the remote controller.
1 parent d937073 commit b9a581c

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

packages/ns-plug/files/ns-plug

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ fi
6565

6666
# Register the server
6767
valid=0
68-
max_attempts=30 # 60 seconds
69-
watchdog=0
7068
response=""
71-
until [ "${valid}" -eq 1 ] || [ "${watchdog}" -ge "${max_attempts}" ]
69+
until [ "${valid}" -eq 1 ]
7270
do
7371
response=$(curl ${curl_opts} -H "Content-Type: application/json" -H "RegistrationToken: ${token}" ${server}/api/units/register -X POST --data '{"unit_id": "'${unit_id}'", "username": "'${user}'", "password": "'${secret}'", "unit_name": "'${unit_name}'", "version": "'${VERSION_ID}'", "subscription_type": "'${subscription_type}'", "system_id": "'${system_id}'"}')
7472
http_code=$(echo ${response} | jq -r '.code // empty')
@@ -82,15 +80,11 @@ do
8280
elif [ "${http_code}" == "200" ]; then
8381
valid=1
8482
else
85-
sleep 2 # wait for controller to be reacheable
86-
watchdog=$(( watchdog + 1 ))
83+
logger -t ns-plug "Connection failed. Waiting for the controller ..."
84+
sleep 5 # wait for controller to be reacheable
8785
fi
8886
done
8987

90-
if [ "${watchdog}" -ge "${max_attempts}" ]; then
91-
exit 5
92-
fi
93-
9488
# Save the new password after successfull registration
9589
uci set rpcd.controller.password=${passwd}
9690
uci commit rpcd

0 commit comments

Comments
 (0)