Skip to content
Snippets Groups Projects
Commit 0f871784 authored by Erick Hitter's avatar Erick Hitter
Browse files

Clean up forwarded sockets before re-forwarding

parent d45eda49
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# #
# Define names for the tunnel to identify them. The list needs to be configured # Define names for the tunnel to identify them. The list needs to be configured
# in the same order as the tunnel config in the TUNELS list. # in the same order as the tunnel config in the TUNNELS list.
# #
#TUNNEL_NAMES=( #TUNNEL_NAMES=(
# "Tunnel-A" # "Tunnel-A"
...@@ -30,6 +30,16 @@ ...@@ -30,6 +30,16 @@
# "-p 1234 username@host2.example.com -L 10002:127.0.0.1:3306 -L 10012:127.0.0.1:27017" # "-p 1234 username@host2.example.com -L 10002:127.0.0.1:3306 -L 10012:127.0.0.1:27017"
#) #)
#
# The SOCKETS array is used to configure sockets forwarded by individual
# ports. Each forwarded socket must be removed before it can be forwarded
# again, which this handles.
#
#SOCKETS=(
# ""
# ""
#)
# #
# The RECONNECT_TIMER is used in case of a tunnel connection to be lost. After # The RECONNECT_TIMER is used in case of a tunnel connection to be lost. After
# the script is detecting that the connection was lost, the time defines the # the script is detecting that the connection was lost, the time defines the
......
...@@ -270,7 +270,7 @@ SCRIPT_PID=$$ ...@@ -270,7 +270,7 @@ SCRIPT_PID=$$
# start procedure according to the action # start procedure according to the action
# #
case $COMMAND in case $COMMAND in
restart) restart)
echotime "COMM - Execute RESTART procedure ... " echotime "COMM - Execute RESTART procedure ... "
$0 --config $CONFIG_FILE stop $COMMAND_INDEX_NAME $0 --config $CONFIG_FILE stop $COMMAND_INDEX_NAME
sleep 2 sleep 2
...@@ -313,8 +313,13 @@ case $COMMAND in ...@@ -313,8 +313,13 @@ case $COMMAND in
kill $PID &>/dev/null kill $PID &>/dev/null
done done
if [ -e "${SOCKETS[$idx]}" ]; then
echo "Removing socket '${SOCKETS[$idx]}' ..."
rm ${SOCKETS[$idx]}
fi
echotime "STOP - Stopped tunnel '${TUNNEL_NAMES[$idx]}' (ID $idx) ... PID: $RESULT_PID" echotime "STOP - Stopped tunnel '${TUNNEL_NAMES[$idx]}' (ID $idx) ... PID: $RESULT_PID"
# check if the tunnels really down # check if the tunnels really down
sleep "0.3" sleep "0.3"
TUNNELS_COUNT=0 TUNNELS_COUNT=0
...@@ -402,6 +407,11 @@ case $COMMAND in ...@@ -402,6 +407,11 @@ case $COMMAND in
echotime "START - Already running tunnel '${TUNNEL_NAMES[$idx]}' (ID $idx) ... PID: $RESULT_PID" echotime "START - Already running tunnel '${TUNNEL_NAMES[$idx]}' (ID $idx) ... PID: $RESULT_PID"
echo "Starting tunnel '${TUNNEL_NAMES[$idx]}' ... Already running" echo "Starting tunnel '${TUNNEL_NAMES[$idx]}' ... Already running"
else else
if [ -e "${SOCKETS[$idx]}" ]; then
echo "Removing socket '${SOCKETS[$idx]}' ..."
rm ${SOCKETS[$idx]}
fi
$0 --config $CONFIG_FILE manage $idx & $0 --config $CONFIG_FILE manage $idx &
sleep "0.2" sleep "0.2"
RESULT_PID=`ps aux | grep -v grep | grep "$0 --config $CONFIG_FILE manage $idx" | awk '{print $2}' | tr '\n' ' '` RESULT_PID=`ps aux | grep -v grep | grep "$0 --config $CONFIG_FILE manage $idx" | awk '{print $2}' | tr '\n' ' '`
...@@ -409,7 +419,7 @@ case $COMMAND in ...@@ -409,7 +419,7 @@ case $COMMAND in
echotime "START - Starting tunnel '${TUNNEL_NAMES[$idx]}' (ID $idx) ... PID: $RESULT_PID" echotime "START - Starting tunnel '${TUNNEL_NAMES[$idx]}' (ID $idx) ... PID: $RESULT_PID"
echo "Starting tunnel '${TUNNEL_NAMES[$idx]}' ... Done" echo "Starting tunnel '${TUNNEL_NAMES[$idx]}' ... Done"
fi fi
# sleep before every cycle to aviod overloading # sleep before every cycle to aviod overloading
done done
echotime "COMM - Execute START procedure ... Done" echotime "COMM - Execute START procedure ... Done"
echotime "" echotime ""
...@@ -430,4 +440,3 @@ case $COMMAND in ...@@ -430,4 +440,3 @@ case $COMMAND in
done done
;; ;;
esac esac
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment