From 4e7f6a31609a5120a722ee6a8d48d55b52fd5b2c Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Tue, 18 Feb 2025 23:49:46 +0530 Subject: [PATCH 01/13] Add healthcheck.sh Added health-check script for ZeroTier Docker --- scripts/healthcheck.sh | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 scripts/healthcheck.sh diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh new file mode 100644 index 0000000..352d58a --- /dev/null +++ b/scripts/healthcheck.sh @@ -0,0 +1,46 @@ +#This health-check script is sponsored by PMGA TECH LLP +#The above line is a part of license to use this code. Removal of line shall be deemed as revoking of usage rights. +#!/bin/sh + +#Exit Codes +# 0= Success +# 1= Failure + +#Environment Variables +# ZT_SPECIFIC_NETWORK= +# ZT_MIN_ROUTES_FOR_HEALTH= + +# Check if Specific Network is specified +if [[ -n "${ZT_SPECIFIC_NETWORK}" ]] ; then + #If Network is OK, continue, else exit + [[ "$(zerotier-cli get ${ZT_SPECIFIC_NETWORK} status)" = "OK" ]] || exit 1 + #echo "${ZT_SPECIFIC_NETWORK} Connected." + exit 0 +# Check for Minimum Networks +elif [[ -n "${ZT_MIN_ROUTES_FOR_HEALTH}" ]] ; then + # Validate the MIN value for Health Checks + ZT_MIN_ROUTES_FOR_HEALTH=$(( ${ZT_MIN_ROUTES_FOR_HEALTH} < 1 ? 1 : ${ZT_MIN_ROUTES_FOR_HEALTH} )) + #echo "No. Of Networks to Check: ${ZT_MIN_ROUTES_FOR_HEALTH}" + network_count=0 + #Get List of Joined networks + joined_networks=$(zerotier-cli listnetworks | awk 'NR>1 {print$3}') + for network in $joined_networks; do + if [[ "$(zerotier-cli get ${network} status)" = "OK" ]] ; then + network_count=$(expr $network_count + 1) + if [[ ${network_count} -ge ${ZT_MIN_ROUTES_FOR_HEALTH} ]] ; then + #echo "${network_count} Networks Connected. Exit Success" + exit 0 + fi + fi + done + #Exit if the above count was not reached + exit 1 +#Check if ALL Networks are connected (Default - ZeroTier) +else + #echo "Checking All Networks" + joined_networks=$(zerotier-cli listnetworks | awk 'NR>1 {print$3}') + for network in $joined_networks; do + [[ "$(zerotier-cli get ${network} status)" = "OK" ]] || exit 1 + #echo "$network Connected." + done +fi From 70dc59596245a4a49e71f6a6a6045537a363f575 Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Wed, 19 Feb 2025 00:04:15 +0530 Subject: [PATCH 02/13] Add Healthcheck to DockerFile Added Healthcheck to DockerFile --- Dockerfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3ceaefe..72cd507 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,9 @@ LABEL org.opencontainers.image.title="zerotier" \ org.opencontainers.image.licenses="MIT" \ org.opencontainers.image.source="https://github.com/zyclonite/zerotier-docker" -COPY --from=builder /src/zerotier-one /scripts/entrypoint.sh /usr/sbin/ +COPY --from=builder /src/zerotier-one /scripts/entrypoint.sh /scripts/healthcheck.sh /usr/sbin/ + +RUN chmod +x /usr/sbin/healthcheck.sh RUN apk add --no-cache --purge --clean-protected libc6-compat libstdc++ \ && mkdir -p /var/lib/zerotier-one \ @@ -40,3 +42,6 @@ EXPOSE 9993/udp ENTRYPOINT ["entrypoint.sh"] CMD ["-U"] + +HEALTHCHECK --interval=60s --timeout=8s --retries=2 --start-period=60s --start-interval=3s \ + CMD ["/bin/sh", "/usr/sbin/healthcheck.sh"] From 07c1868db008dbd60ec0571bea82cbc2ba6bdafe Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Wed, 19 Feb 2025 00:22:14 +0530 Subject: [PATCH 03/13] Update healthcheck.sh (Change Env. Variable Names) Changed ENV Variable Names for better understanding --- scripts/healthcheck.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index 352d58a..d386adf 100644 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -7,27 +7,27 @@ # 1= Failure #Environment Variables -# ZT_SPECIFIC_NETWORK= -# ZT_MIN_ROUTES_FOR_HEALTH= +# CHK_ZT_SPECIFIC_NETWORK= +# CHK_ZT_MIN_ROUTES_FOR_HEALTH= # Check if Specific Network is specified -if [[ -n "${ZT_SPECIFIC_NETWORK}" ]] ; then +if [[ -n "${CHK_ZT_SPECIFIC_NETWORK}" ]] ; then #If Network is OK, continue, else exit - [[ "$(zerotier-cli get ${ZT_SPECIFIC_NETWORK} status)" = "OK" ]] || exit 1 - #echo "${ZT_SPECIFIC_NETWORK} Connected." + [[ "$(zerotier-cli get ${CHK_ZT_SPECIFIC_NETWORK} status)" = "OK" ]] || exit 1 + #echo "${CHK_ZT_SPECIFIC_NETWORK} Connected." exit 0 # Check for Minimum Networks -elif [[ -n "${ZT_MIN_ROUTES_FOR_HEALTH}" ]] ; then +elif [[ -n "${CHK_ZT_MIN_ROUTES_FOR_HEALTH}" ]] ; then # Validate the MIN value for Health Checks - ZT_MIN_ROUTES_FOR_HEALTH=$(( ${ZT_MIN_ROUTES_FOR_HEALTH} < 1 ? 1 : ${ZT_MIN_ROUTES_FOR_HEALTH} )) - #echo "No. Of Networks to Check: ${ZT_MIN_ROUTES_FOR_HEALTH}" + CHK_ZT_MIN_ROUTES_FOR_HEALTH=$(( ${CHK_ZT_MIN_ROUTES_FOR_HEALTH} < 1 ? 1 : ${CHK_ZT_MIN_ROUTES_FOR_HEALTH} )) + #echo "No. Of Networks to Check: ${CHK_ZT_MIN_ROUTES_FOR_HEALTH}" network_count=0 #Get List of Joined networks joined_networks=$(zerotier-cli listnetworks | awk 'NR>1 {print$3}') for network in $joined_networks; do if [[ "$(zerotier-cli get ${network} status)" = "OK" ]] ; then network_count=$(expr $network_count + 1) - if [[ ${network_count} -ge ${ZT_MIN_ROUTES_FOR_HEALTH} ]] ; then + if [[ ${network_count} -ge ${CHK_ZT_MIN_ROUTES_FOR_HEALTH} ]] ; then #echo "${network_count} Networks Connected. Exit Success" exit 0 fi From 2db4553664540a67ef2021ba1a3f310aaeacb385 Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Wed, 19 Feb 2025 20:07:58 +0530 Subject: [PATCH 04/13] Update healthcheck.sh Added additional check for healthcheck failure in case of no joined networks. --- scripts/healthcheck.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index d386adf..428aaac 100644 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -39,6 +39,8 @@ elif [[ -n "${CHK_ZT_MIN_ROUTES_FOR_HEALTH}" ]] ; then else #echo "Checking All Networks" joined_networks=$(zerotier-cli listnetworks | awk 'NR>1 {print$3}') + #If there are no Networks, exit Failure + [[ -n ${joined_networks} ]] || exit 1 for network in $joined_networks; do [[ "$(zerotier-cli get ${network} status)" = "OK" ]] || exit 1 #echo "$network Connected." From 53789fac8a3e496a458ab1b0546315b63a82fe0c Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Wed, 19 Feb 2025 20:20:43 +0530 Subject: [PATCH 05/13] Update README.md Updated README.md to reflect new Environment Variables for Health-Checks --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 06d8641..b0343c3 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,27 @@ or create an empty file with the network as name /var/lib/zerotier-one/networks.d/8056c2e21c000001.conf +#### Health Checks + +Environment Variable Options: + + 1. Check For Specific Network: + + + CHK_ZT_SPECIFIC_NETWORK=[Enter 1 Specific Network for Checking; CHK_ZT_MIN_ROUTES_FOR_HEALTH is ignored if this is used.] + + + 2. Check for Minimum number of Connections: + + + CHK_ZT_MIN_ROUTES_FOR_HEALTH=[Should be a Number greater than 0; Ignored if CHK_ZT_SPECIFIC_NETWORK is used.] + + + 3. Check for ALL Networks to be connected: + This is default mode when no Environment variable is defined. + + + #### Router mode A variation on the container which implements a local network router. See: From 0e9c0c52acacafe1933f6177a681fec8b8c45d89 Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Wed, 19 Feb 2025 15:31:57 +0000 Subject: [PATCH 06/13] Updated Script to Check for Specific Networks (Multiple instead of 1) --- README.md | 4 ++-- scripts/healthcheck.sh | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b0343c3..c7e73d2 100644 --- a/README.md +++ b/README.md @@ -36,10 +36,10 @@ or create an empty file with the network as name Environment Variable Options: - 1. Check For Specific Network: + 1. Check For Specific Networks: - CHK_ZT_SPECIFIC_NETWORK=[Enter 1 Specific Network for Checking; CHK_ZT_MIN_ROUTES_FOR_HEALTH is ignored if this is used.] + CHK_ZT_SPECIFIC_NETWORKS=[Enter Specific Networks for checking with a space between each network; ALL Networks mentioned here would be checked; CHK_ZT_MIN_ROUTES_FOR_HEALTH is ignored if this is used.] 2. Check for Minimum number of Connections: diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index 428aaac..d6814a2 100644 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -1,5 +1,4 @@ #This health-check script is sponsored by PMGA TECH LLP -#The above line is a part of license to use this code. Removal of line shall be deemed as revoking of usage rights. #!/bin/sh #Exit Codes @@ -7,14 +6,16 @@ # 1= Failure #Environment Variables -# CHK_ZT_SPECIFIC_NETWORK= +# CHK_ZT_SPECIFIC_NETWORKS= # CHK_ZT_MIN_ROUTES_FOR_HEALTH= -# Check if Specific Network is specified -if [[ -n "${CHK_ZT_SPECIFIC_NETWORK}" ]] ; then - #If Network is OK, continue, else exit - [[ "$(zerotier-cli get ${CHK_ZT_SPECIFIC_NETWORK} status)" = "OK" ]] || exit 1 - #echo "${CHK_ZT_SPECIFIC_NETWORK} Connected." +# Check if specified Networks are all Connected +if [[ -n "${CHK_ZT_SPECIFIC_NETWORKS}" ]] ; then + for network in $CHK_ZT_SPECIFIC_NETWORKS; do + #If Network is OK, continue, else exit + [[ "$(zerotier-cli get ${network} status)" = "OK" ]] || exit 1 + #echo "${CHK_ZT_SPECIFIC_NETWORKS} Connected." + done exit 0 # Check for Minimum Networks elif [[ -n "${CHK_ZT_MIN_ROUTES_FOR_HEALTH}" ]] ; then @@ -45,4 +46,4 @@ else [[ "$(zerotier-cli get ${network} status)" = "OK" ]] || exit 1 #echo "$network Connected." done -fi +fi \ No newline at end of file From eebff42ec07d03704647b0ac1615c281e5ad55bc Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Fri, 21 Feb 2025 12:19:33 +0000 Subject: [PATCH 07/13] Minor Fix --- scripts/healthcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index d6814a2..e3eba21 100644 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -41,7 +41,7 @@ else #echo "Checking All Networks" joined_networks=$(zerotier-cli listnetworks | awk 'NR>1 {print$3}') #If there are no Networks, exit Failure - [[ -n ${joined_networks} ]] || exit 1 + [[ -n "${joined_networks}" ]] || exit 1 for network in $joined_networks; do [[ "$(zerotier-cli get ${network} status)" = "OK" ]] || exit 1 #echo "$network Connected." From a1755b2d2fc985ecd680c337b7a52612e14a2a67 Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Sat, 22 Feb 2025 19:29:10 +0000 Subject: [PATCH 08/13] Added Enhanced-AutoJoin Feature --- README.md | 24 ++++++++++++++++++------ scripts/entrypoint-router.sh | 34 ++++++++++++++++++++++++++++++++++ scripts/entrypoint.sh | 34 ++++++++++++++++++++++++++++++++++ scripts/healthcheck.sh | 18 +++++++++--------- 4 files changed, 95 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c7e73d2..c64da07 100644 --- a/README.md +++ b/README.md @@ -32,21 +32,33 @@ or create an empty file with the network as name /var/lib/zerotier-one/networks.d/8056c2e21c000001.conf +#### Auto-Join Networks + +Define: + +``` +ZT_NETWORK_IDS= [Network IDs with Space in between each ID] +``` + + +The container will JOIN ALL the Networks mentioned in this variable and LEAVE ANY OTHER Network NOT defined in this variable. + + #### Health Checks Environment Variable Options: 1. Check For Specific Networks: - - CHK_ZT_SPECIFIC_NETWORKS=[Enter Specific Networks for checking with a space between each network; ALL Networks mentioned here would be checked; CHK_ZT_MIN_ROUTES_FOR_HEALTH is ignored if this is used.] - + ``` + ZT_CHK_SPECIFIC_NETWORKS=[Enter Specific Networks for checking with a space between each network; ALL Networks mentioned here would be checked; ZT_CHK_MIN_ROUTES_FOR_HEALTH is ignored if this is used.] + ``` 2. Check for Minimum number of Connections: - - CHK_ZT_MIN_ROUTES_FOR_HEALTH=[Should be a Number greater than 0; Ignored if CHK_ZT_SPECIFIC_NETWORK is used.] - + ``` + ZT_CHK_MIN_ROUTES_FOR_HEALTH=[Should be a Number greater than 0; Ignored if CHK_ZT_SPECIFIC_NETWORK is used.] + ``` 3. Check for ALL Networks to be connected: This is default mode when no Environment variable is defined. diff --git a/scripts/entrypoint-router.sh b/scripts/entrypoint-router.sh index 825dfec..a1374fa 100755 --- a/scripts/entrypoint-router.sh +++ b/scripts/entrypoint-router.sh @@ -22,6 +22,40 @@ if [ ! -d "${NETWORKS_DIR}" -a -n "${ZEROTIER_ONE_NETWORK_IDS}" ] ; then done fi +#Match Networks with User Provided Networks +# Check if ZT_NETWORK_IDS is not NULL +if [[ -n "$ZT_NETWORK_IDS" ]] ; then + #First leave networks not a part of user provided networks + current_joined_networks=$(zerotier-cli listnetworks | awk 'NR>1 {print$3}') + for current_network in $current_joined_networks; do + found_network=0 + for zt_network in $ZT_NETWORK_IDS; do + if [[ "$current_network" = "$zt_network" ]]; then + found_network=1 + break 1; + fi + done + if [[ $found_network -eq 0 ]]; then + zerotier-cli leave $current_network + fi + done + #Join Networks not present + #Resetting joined Networks for optimisation + current_joined_networks=$(zerotier-cli listnetworks | awk 'NR>1 {print$3}') + for zt_network in $ZT_NETWORK_IDS; do + found_network=0 + for current_network in $current_joined_networks; do + if [[ "$current_network" = "$zt_network" ]]; then + found_network=1 + break 1; + fi + done + if [[ $found_network -eq 0 ]]; then + zerotier-cli join $zt_network + fi + done +fi + # make sure permissions are always as expected (self-repair) PUID="${PUID:-"999"}" PGID="${PGID:-"994"}" diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index df5bbf1..8086991 100755 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -9,6 +9,40 @@ DEFAULT_PRIMARY_PORT=9993 DEFAULT_PORT_MAPPING_ENABLED=true DEFAULT_ALLOW_TCP_FALLBACK_RELAY=true +#Match Networks with User Provided Networks +# Check if ZT_NETWORK_IDS is not NULL +if [[ -n "$ZT_NETWORK_IDS" ]] ; then + #First leave networks not a part of user provided networks + current_joined_networks=$(zerotier-cli listnetworks | awk 'NR>1 {print$3}') + for current_network in $current_joined_networks; do + found_network=0 + for zt_network in $ZT_NETWORK_IDS; do + if [[ "$current_network" = "$zt_network" ]]; then + found_network=1 + break 1; + fi + done + if [[ $found_network -eq 0 ]]; then + zerotier-cli leave $current_network + fi + done + #Join Networks not present + #Resetting joined Networks for optimisation + current_joined_networks=$(zerotier-cli listnetworks | awk 'NR>1 {print$3}') + for zt_network in $ZT_NETWORK_IDS; do + found_network=0 + for current_network in $current_joined_networks; do + if [[ "$current_network" = "$zt_network" ]]; then + found_network=1 + break 1; + fi + done + if [[ $found_network -eq 0 ]]; then + zerotier-cli join $zt_network + fi + done +fi + MANAGEMENT_NETWORKS="" if [ ! -z "$ZT_ALLOW_MANAGEMENT_FROM" ]; then for NETWORK in ${ZT_ALLOW_MANAGEMENT_FROM//,/$IFS}; do diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index e3eba21..d216adf 100644 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -6,29 +6,29 @@ # 1= Failure #Environment Variables -# CHK_ZT_SPECIFIC_NETWORKS= -# CHK_ZT_MIN_ROUTES_FOR_HEALTH= +# ZT_CHK_SPECIFIC_NETWORKS= +# ZT_CHK_MIN_ROUTES_FOR_HEALTH= # Check if specified Networks are all Connected -if [[ -n "${CHK_ZT_SPECIFIC_NETWORKS}" ]] ; then - for network in $CHK_ZT_SPECIFIC_NETWORKS; do +if [[ -n "${ZT_CHK_SPECIFIC_NETWORKS}" ]] ; then + for network in $ZT_CHK_SPECIFIC_NETWORKS; do #If Network is OK, continue, else exit [[ "$(zerotier-cli get ${network} status)" = "OK" ]] || exit 1 - #echo "${CHK_ZT_SPECIFIC_NETWORKS} Connected." + #echo "${ZT_CHK_SPECIFIC_NETWORKS} Connected." done exit 0 # Check for Minimum Networks -elif [[ -n "${CHK_ZT_MIN_ROUTES_FOR_HEALTH}" ]] ; then +elif [[ -n "${ZT_CHK_MIN_ROUTES_FOR_HEALTH}" ]] ; then # Validate the MIN value for Health Checks - CHK_ZT_MIN_ROUTES_FOR_HEALTH=$(( ${CHK_ZT_MIN_ROUTES_FOR_HEALTH} < 1 ? 1 : ${CHK_ZT_MIN_ROUTES_FOR_HEALTH} )) - #echo "No. Of Networks to Check: ${CHK_ZT_MIN_ROUTES_FOR_HEALTH}" + ZT_CHK_MIN_ROUTES_FOR_HEALTH=$(( ${ZT_CHK_MIN_ROUTES_FOR_HEALTH} < 1 ? 1 : ${ZT_CHK_MIN_ROUTES_FOR_HEALTH} )) + #echo "No. Of Networks to Check: ${ZT_CHK_MIN_ROUTES_FOR_HEALTH}" network_count=0 #Get List of Joined networks joined_networks=$(zerotier-cli listnetworks | awk 'NR>1 {print$3}') for network in $joined_networks; do if [[ "$(zerotier-cli get ${network} status)" = "OK" ]] ; then network_count=$(expr $network_count + 1) - if [[ ${network_count} -ge ${CHK_ZT_MIN_ROUTES_FOR_HEALTH} ]] ; then + if [[ ${network_count} -ge ${ZT_CHK_MIN_ROUTES_FOR_HEALTH} ]] ; then #echo "${network_count} Networks Connected. Exit Success" exit 0 fi From a8842dfcf81dbe41d2d0a53f2dfb7cc6822df635 Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Sat, 22 Feb 2025 19:35:06 +0000 Subject: [PATCH 09/13] Updated Dockerfile & Compose --- Dockerfile | 2 +- docker-compose-router.yml | 6 +++++- docker-compose.yml | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 72cd507..076c074 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ARG ALPINE_VERSION=3.21 ARG ZT_COMMIT=185a3a2c76e6bf1b1c0415871f43076638eb007c ARG ZT_VERSION=1.14.2 -FROM ${ALPINE_IMAGE}:${ALPINE_VERSION} as builder +FROM ${ALPINE_IMAGE}:${ALPINE_VERSION} AS builder ARG ZT_COMMIT diff --git a/docker-compose-router.yml b/docker-compose-router.yml index c09319e..b3041ac 100644 --- a/docker-compose-router.yml +++ b/docker-compose-router.yml @@ -20,4 +20,8 @@ services: - ZEROTIER_ONE_LOCAL_PHYS=eth0 - ZEROTIER_ONE_USE_IPTABLES_NFT=false - ZEROTIER_ONE_GATEWAY_MODE=inbound - # - ZEROTIER_ONE_NETWORK_IDS=yourNetworkID + #Variables For AutoJoin + #- ZT_NETWORK_IDS + #Variables for Health-Check + #- ZT_CHK_SPECIFIC_NETWORKS + #- ZT_CHK_MIN_ROUTES_FOR_HEALTH \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 87292a7..f9298ee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,3 +11,9 @@ services: cap_add: - NET_ADMIN - SYS_ADMIN + #environment: + #Variables For AutoJoin + #- ZT_NETWORK_IDS + #Variables for Health-Check + #- ZT_CHK_SPECIFIC_NETWORKS + #- ZT_CHK_MIN_ROUTES_FOR_HEALTH \ No newline at end of file From 9e9978162a6970ffd77cff9185dfad15c6e5b15e Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Fri, 28 Feb 2025 18:12:14 +0000 Subject: [PATCH 10/13] Added Route Checking in addition to Status Check. --- scripts/healthcheck.sh | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index d216adf..cb622cc 100644 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -13,8 +13,21 @@ if [[ -n "${ZT_CHK_SPECIFIC_NETWORKS}" ]] ; then for network in $ZT_CHK_SPECIFIC_NETWORKS; do #If Network is OK, continue, else exit - [[ "$(zerotier-cli get ${network} status)" = "OK" ]] || exit 1 - #echo "${ZT_CHK_SPECIFIC_NETWORKS} Connected." + if [[ "$(zerotier-cli get ${network} status)" = "OK" ]]; then + #Check for Routes + interface=$(zerotier-cli get ${network} portDeviceName) + routes=$(ip r | grep "dev ${interface}" | grep -cv "via") + #Exit if No routes + if [[ ${routes} -lt 1 ]]; then + exit 1 + else + continue + #echo "${network} Connected." + fi + #Network Status Not = OK + else + exit 1 + fi done exit 0 # Check for Minimum Networks @@ -27,7 +40,15 @@ elif [[ -n "${ZT_CHK_MIN_ROUTES_FOR_HEALTH}" ]] ; then joined_networks=$(zerotier-cli listnetworks | awk 'NR>1 {print$3}') for network in $joined_networks; do if [[ "$(zerotier-cli get ${network} status)" = "OK" ]] ; then - network_count=$(expr $network_count + 1) + #Check for Routes + interface=$(zerotier-cli get ${network} portDeviceName) + routes=$(ip r | grep "dev ${interface}" | grep -cv "via") + if [[ ${routes} -lt 1 ]]; then + exit 1 + else + network_count=$(expr $network_count + 1) + #echo "${network} Connected." + fi if [[ ${network_count} -ge ${ZT_CHK_MIN_ROUTES_FOR_HEALTH} ]] ; then #echo "${network_count} Networks Connected. Exit Success" exit 0 @@ -43,7 +64,18 @@ else #If there are no Networks, exit Failure [[ -n "${joined_networks}" ]] || exit 1 for network in $joined_networks; do - [[ "$(zerotier-cli get ${network} status)" = "OK" ]] || exit 1 - #echo "$network Connected." + #[[ "$(zerotier-cli get ${network} status)" = "OK" ]] || exit 1 + if [[ "$(zerotier-cli get ${network} status)" = "OK" ]]; then + #Check for Routes + interface=$(zerotier-cli get ${network} portDeviceName) + routes=$(ip r | grep "dev ${interface}" | grep -cv "via") + #Exit if No routes + if [[ ${routes} -lt 1 ]]; then + exit 1 + else + continue + #echo "${network} Connected." + fi + fi done fi \ No newline at end of file From 5c6b562fd29dc9fd4239da141e0f5e24bbb09b89 Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Tue, 4 Mar 2025 21:02:42 +0000 Subject: [PATCH 11/13] Update License Text --- scripts/healthcheck.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index cb622cc..7349646 100644 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -1,6 +1,14 @@ -#This health-check script is sponsored by PMGA TECH LLP #!/bin/sh - +#This health-check script is sponsored by PMGA TECH LLP +#Licensing Terms: +#This code is free to use, ditribute, use as a derivative for another code or do any such activity as allowed by M.I.T License as long as the recognition stays intact. +#The recognition may be moved to the CONTRIBUTERS.md file in case the same is being maintained in the projects in which the code is being used. +#Removing the recognition text shall construe revocation of usage rights and thus would be deemed as a copyright infringement. +#The intent of this license is ONLY to give due recognition to the contributers and there is no other intent whatsoever. +# Contributers: +# PMGA Tech LLP +# gb-123-git + #Exit Codes # 0= Success # 1= Failure From 1cef642c939e788f09424934eb8bd44056421332 Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Wed, 5 Mar 2025 02:55:47 +0530 Subject: [PATCH 12/13] Update License Text (SpellFix) Spell-Checked Licensing Text --- scripts/healthcheck.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index 7349646..d2d197b 100644 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -1,7 +1,7 @@ #!/bin/sh #This health-check script is sponsored by PMGA TECH LLP #Licensing Terms: -#This code is free to use, ditribute, use as a derivative for another code or do any such activity as allowed by M.I.T License as long as the recognition stays intact. +#This code is free to use, distribute, use as a derivative for another code or do any such activity as allowed by M.I.T License as long as the recognition stays intact. #The recognition may be moved to the CONTRIBUTERS.md file in case the same is being maintained in the projects in which the code is being used. #Removing the recognition text shall construe revocation of usage rights and thus would be deemed as a copyright infringement. #The intent of this license is ONLY to give due recognition to the contributers and there is no other intent whatsoever. @@ -86,4 +86,4 @@ else fi fi done -fi \ No newline at end of file +fi From 09193bc9884ce28005f038ce0bc28c4c2c241956 Mon Sep 17 00:00:00 2001 From: gb-123-git <64229388+gb-123-git@users.noreply.github.com> Date: Thu, 3 Apr 2025 01:49:07 +0530 Subject: [PATCH 13/13] Update healthcheck.sh (Change License Text) Update License Text --- scripts/healthcheck.sh | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh index d2d197b..4d280b3 100644 --- a/scripts/healthcheck.sh +++ b/scripts/healthcheck.sh @@ -1,13 +1,29 @@ #!/bin/sh -#This health-check script is sponsored by PMGA TECH LLP -#Licensing Terms: -#This code is free to use, distribute, use as a derivative for another code or do any such activity as allowed by M.I.T License as long as the recognition stays intact. -#The recognition may be moved to the CONTRIBUTERS.md file in case the same is being maintained in the projects in which the code is being used. -#Removing the recognition text shall construe revocation of usage rights and thus would be deemed as a copyright infringement. -#The intent of this license is ONLY to give due recognition to the contributers and there is no other intent whatsoever. -# Contributers: +#MIT License +# +#Copyright (c) PMGA Tech LLP +# +#Contributers: # PMGA Tech LLP # gb-123-git +# +#Permission is hereby granted, free of charge, to any person obtaining a copy +#of this software and associated documentation files (the "Software"), to deal +#in the Software without restriction, including without limitation the rights +#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +#copies of the Software, and to permit persons to whom the Software is +#furnished to do so, subject to the following conditions: +# +#The above copyright notice and this permission notice alongwith the following +#paragraph shall be included in all copies or substantial portions of the Software. +# +#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +#SOFTWARE. #Exit Codes # 0= Success