Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller: Handle empty HTTP response and add restart functionality for ns-plug service #977

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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.
  • Loading branch information
gsanchietti committed Dec 18, 2024
commit b9a581c739ecb99d32497be5bf6589db0c14c526
12 changes: 3 additions & 9 deletions packages/ns-plug/files/ns-plug
Original file line number Diff line number Diff line change
@@ -65,10 +65,8 @@ fi

# Register the server
valid=0
max_attempts=30 # 60 seconds
watchdog=0
response=""
until [ "${valid}" -eq 1 ] || [ "${watchdog}" -ge "${max_attempts}" ]
until [ "${valid}" -eq 1 ]
do
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}'"}')
http_code=$(echo ${response} | jq -r '.code // empty')
@@ -82,15 +80,11 @@ do
elif [ "${http_code}" == "200" ]; then
valid=1
else
sleep 2 # wait for controller to be reacheable
watchdog=$(( watchdog + 1 ))
logger -t ns-plug "Connection failed. Waiting for the controller ..."
sleep 5 # wait for controller to be reacheable
fi
done

if [ "${watchdog}" -ge "${max_attempts}" ]; then
exit 5
fi

# Save the new password after successfull registration
uci set rpcd.controller.password=${passwd}
uci commit rpcd
Loading