Skip to content

Commit

Permalink
watch connection and restart if need it
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Guti committed Oct 15, 2021
1 parent f299eae commit 30c5362
Showing 8 changed files with 28 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -21,4 +21,4 @@ RUN apt-get update -y && \

COPY /rootfs /
ENV S6_CMD_WAIT_FOR_SERVICES=1
CMD nord_login && nord_config && nord_connect && sleep infinity & wait
CMD nord_login && nord_config && nord_connect && nord_watch
1 change: 1 addition & 0 deletions rootfs/etc/fix-attrs.d/nord_utils
Original file line number Diff line number Diff line change
@@ -2,3 +2,4 @@
/usr/bin/nord_connect false root:root 0755 0755
/usr/bin/nord_login false root:root 0755 0755
/usr/bin/nord_private_key false root:root 0755 0755
/usr/bin/nord_watch false root:root 0755 0755
2 changes: 0 additions & 2 deletions rootfs/etc/services.d/nordvpn/finish
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/bash

nordvpn disconnect
nordvpn logout
rm -rf /run/nordvpn
1 change: 1 addition & 0 deletions rootfs/etc/services.d/nordvpn/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
12 changes: 11 additions & 1 deletion rootfs/usr/bin/nord_connect
Original file line number Diff line number Diff line change
@@ -2,7 +2,17 @@

[[ -n ${PRE_CONNECT} ]] && eval ${PRE_CONNECT}

nordvpn connect ${CONNECT}
echo "Connecting..."
current_sleep=1
until nordvpn connect ${CONNECT}; do
if [ ${current_sleep} -gt 4096 ]; then
echo "Unable to connect."
exit 1
fi
echo "Unable to connect retrying in ${current_sleep} seconds."
sleep ${current_sleep}
current_sleep=$((current_sleep * 2))
done

[[ -n ${POST_CONNECT} ]] && eval ${POST_CONNECT}

2 changes: 2 additions & 0 deletions rootfs/usr/bin/nord_private_key
Original file line number Diff line number Diff line change
@@ -3,8 +3,10 @@
nord_login
nord_config
nord_connect

echo "############################################################"
echo "IP: $(ip -o addr show dev nordlynx | awk '$3 == "inet" {print $4}')"
echo "Private Key: $(wg show nordlynx private-key)"
echo "############################################################"

exit 0
12 changes: 12 additions & 0 deletions rootfs/usr/bin/nord_watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

while true; do
sleep "${CHECK_CONNECTION_INTERVAL:-300}"
if [[ ! $(curl -Is -m 30 -o /dev/null -w "%{http_code}" "${CHECK_CONNECTION_URL:-www.google.com}") =~ ^[23] ]]; then
echo "Unstable connection detected!"
nordvpn status

s6-svc -wR -t /var/run/s6/services/nordvpn
nord_connect
fi
done
58 changes: 0 additions & 58 deletions start_vpn.sh

This file was deleted.

0 comments on commit 30c5362

Please sign in to comment.