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

revert: feat(ns-plug): restart service if connection goes down #1083

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion packages/ns-plug/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ define Package/ns-plug/install
$(INSTALL_DIR) $(1)/usr/libexec/mwan-hooks
$(INSTALL_BIN) ./files/ns-plug.init $(1)/etc/init.d/ns-plug
$(INSTALL_BIN) ./files/ns-plug $(1)/usr/sbin/ns-plug
$(INSTALL_BIN) ./files/restart-ns-plug $(1)/usr/libexec/restart-ns-plug
$(INSTALL_BIN) ./files/distfeed-setup $(1)/usr/sbin/distfeed-setup
$(INSTALL_BIN) ./files/remote-backup $(1)/usr/sbin
$(INSTALL_BIN) ./files/send-backup $(1)/usr/sbin
Expand Down
15 changes: 10 additions & 5 deletions packages/ns-plug/files/ns-plug
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ fi

# Register the server
valid=0
max_attempts=30 # 60 seconds
watchdog=0
response=""
until [ "${valid}" -eq 1 ]
until [ "${valid}" -eq 1 ] || [ "${watchdog}" -ge "${max_attempts}" ]
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')
http_code=$(echo ${response} | jq -r .code)
if [ "${http_code}" == "409" ]; then
# Duplicate entry, cleanup uci config
uci delete rpcd.controller
Expand All @@ -80,11 +82,15 @@ do
elif [ "${http_code}" == "200" ]; then
valid=1
else
logger -t ns-plug "Connection failed. Waiting for the controller ..."
sleep 5 # wait for controller to be reacheable
sleep 2 # wait for controller to be reacheable
watchdog=$(( watchdog + 1 ))
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
Expand All @@ -106,7 +112,6 @@ dev tun-nsplug
tls-client
script-security 2
route-up /usr/sbin/ns-controller-push-info
down "/usr/libexec/restart-ns-plug"
<ca>
${ca}
</ca>
Expand Down
21 changes: 0 additions & 21 deletions packages/ns-plug/files/restart-ns-plug

This file was deleted.

Loading