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 @@
#
# 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-A"
......@@ -30,6 +30,16 @@
# "-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 script is detecting that the connection was lost, the time defines the
......
......@@ -270,7 +270,7 @@ SCRIPT_PID=$$
# start procedure according to the action
#
case $COMMAND in
restart)
restart)
echotime "COMM - Execute RESTART procedure ... "
$0 --config $CONFIG_FILE stop $COMMAND_INDEX_NAME
sleep 2
......@@ -313,8 +313,13 @@ case $COMMAND in
kill $PID &>/dev/null
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"
# check if the tunnels really down
sleep "0.3"
TUNNELS_COUNT=0
......@@ -402,6 +407,11 @@ case $COMMAND in
echotime "START - Already running tunnel '${TUNNEL_NAMES[$idx]}' (ID $idx) ... PID: $RESULT_PID"
echo "Starting tunnel '${TUNNEL_NAMES[$idx]}' ... Already running"
else
if [ -e "${SOCKETS[$idx]}" ]; then
echo "Removing socket '${SOCKETS[$idx]}' ..."
rm ${SOCKETS[$idx]}
fi
$0 --config $CONFIG_FILE manage $idx &
sleep "0.2"
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
echotime "START - Starting tunnel '${TUNNEL_NAMES[$idx]}' (ID $idx) ... PID: $RESULT_PID"
echo "Starting tunnel '${TUNNEL_NAMES[$idx]}' ... Done"
fi
# sleep before every cycle to aviod overloading
# sleep before every cycle to aviod overloading
done
echotime "COMM - Execute START procedure ... Done"
echotime ""
......@@ -430,4 +440,3 @@ case $COMMAND in
done
;;
esac
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment