Skip to content

Commit 7889467

Browse files
committed
Debug tunmgrd.
1 parent 1f94eab commit 7889467

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

tunmgrd/tunmgrd

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,11 @@ source bashlib #
2626

2727
# Load and parse the tunnel configuration file.
2828
cd
29-
TMPDIR=${TMPDIR:-/tmp} TMPDIR=${TMPDIR%/}
30-
_logVerbosity=2 logDir= config=()
29+
config=()
3130
source "$HOME/.tunmgrd.conf"
3231
: ${logDir:=$TMPDIR}
33-
[[ -t 1 ]]
34-
: ${logColor:=$(( ! $? ))}
3532
_logFile=$logDir/tunmgrd.log
36-
_logColor=$logColor
33+
loopDelay=3
3734
for ((t=0; t < ${#config[@]}; ++t)); do
3835
read urls[t] modifiers[t] configs[t] <<< "${config[t]}"
3936
done
@@ -89,11 +86,12 @@ while true; do
8986
schema=${urls[t]%%://*}
9087
case "$schema" in
9188
ssh) port=${port:-22} ;;
92-
http) port=${port:-80} ;;
93-
https) port=${port:-443} ;;
89+
http) host=${host%%/*} port=${port:-80} ;;
90+
https) host=${host%%/*} port=${port:-443} ;;
9491
esac
9592

9693
# Can we get a response over the connection? -> up
94+
dbg 'Looking for activity for: %s (%s)' "${urls[t]}" "${out[t]}"
9795
if [[ ${out[t]} ]] && {
9896
read -d ''
9997
for tries in {1..3}; do
@@ -109,6 +107,7 @@ while true; do
109107
fi
110108

111109
# No response received - Is the process alive? -> lag
110+
dbg 'No activity, checking if controller(pid: %s, %s) is alive: %s' "${pid[t]}" "${state[t]}" "${urls[t]}"
112111
if kill -0 "${pid[t]}" 2>/dev/null; then
113112
[[ ${state[t]} != @(conn|lag) ]] && {
114113
state[t]=lag
@@ -118,6 +117,7 @@ while true; do
118117
fi
119118

120119
# Process disappeared. -> down
120+
dbg 'No controller, cleaning up: %s' "${urls[t]}"
121121
[[ ${state[t]} != @(n/a|down|) ]] && {
122122
state[t]=down
123123
perr 'Connection Lost: %s' "${urls[t]}"
@@ -128,6 +128,7 @@ while true; do
128128

129129

130130
# No process, check service availability. -> unavailable
131+
dbg 'Checking if available: %s (%s:%s)' "${urls[t]}" "$host" "$port"
131132
if ! nc -z "$host" "$port" &>/dev/null; then
132133
[[ ${state[t]} != n/a ]] && {
133134
wrn 'Connection Unavailable: %s - %s:%d' "${urls[t]}" "$host" "$port"
@@ -177,8 +178,10 @@ while true; do
177178
;;
178179

179180
http*)
180-
curl -sSnfo - "$url" >"${out[t]}" 2>"${err[t]}" &
181+
set -x
182+
curl -sSnfo - "${urls[t]}" >"${out[t]}" 2>"${err[t]}" &
181183
state[t]=conn pid[t]=$!
184+
set +x
182185
;;
183186

184187
*)
@@ -187,5 +190,6 @@ while true; do
187190
esac
188191
done
189192

190-
sleep 1
193+
dbg 'Restarting in %ss' "$loopDelay"
194+
sleep "$loopDelay"
191195
done

0 commit comments

Comments
 (0)