sshtunnel: bug fix
authorNuno Goncalves <nunojpg@gmail.com>
Wed, 22 Dec 2010 23:14:01 +0000 (23:14 +0000)
committerNuno Goncalves <nunojpg@gmail.com>
Wed, 22 Dec 2010 23:14:01 +0000 (23:14 +0000)
SVN-Revision: 24807

net/sshtunnel/files/initd_sshtunnel
net/sshtunnel/files/sshtunnel.sh

index 3c8c26465f4d38e5e52a261874fbbb19f260e2bd..3e585634d139cd62a4be37624bbd00e636e59787 100644 (file)
@@ -135,11 +135,11 @@ load_server() {
        [ -n "$error" ]         && { logger -p user.err -t "sshtunnel" "tunnels to $server not started - $error"; return; }
        [ "$count" -eq 0 ]      && { logger -p user.err -t "sshtunnel" "tunnels to $server not started - no tunnels defined"; return; }
 
-       append_params CheckHostIP Compression CompressionLevel IdentityFile LogLevel PKCS11Provider ServerAliveCountMax ServerAliveInterval StrickHostKeyChecking TCPKeepAlive VerifyHostKeyDNS
+       append_params CheckHostIP Compression CompressionLevel IdentityFile LogLevel PKCS11Provider ServerAliveCountMax ServerAliveInterval StrictHostKeyChecking TCPKeepAlive VerifyHostKeyDNS
        ARGS="$ARGS_options -o ExitOnForwardFailure=yes -o BatchMode=yes -nN $ARGS_tunnels $user@$hostname"
 
        /usr/bin/sshtunnel.sh "$ARGS" "$retrydelay" "$server" &
-       echo $! >> "$PIDFILE".pids
+       echo $! >> "${PIDFILE}.pids"
        logger -p user.info -t "sshtunnel" "started tunnels to $server (pid=$!;retrydelay=$retrydelay)" 
 }
 
@@ -150,13 +150,18 @@ stop() {
                 
                 while read pid
                 do
-                       start-stop-daemon -K -p "$PIDFILE"_"$pid".pid
-                       kill $pid
+                       kill "$pid"     # kill mother process first
+
+                       [ -f "${PIDFILE}_${pid}.pid" ] && { # if ssh was running, kill it also (mother process could be in retry wait)
+                               start-stop-daemon -K -p "${PIDFILE}_${pid}.pid"
+                               rm "${PIDFILE}_${pid}.pid"
+                       }
+                       
                        logger -p daemon.info -t "sshtunnel[$pid]" "tunnel stopped"
-                       rm "$PIDFILE"_"$pid".pid
-               done < "$PIDFILE".pids
+                       
+               done < "${PIDFILE}.pids"
 
-               rm "$PIDFILE".pids
+               rm "${PIDFILE}.pids"
 
                 logger -p user.info -t "sshtunnel" "all tunnels stopped"
         else
@@ -165,7 +170,7 @@ stop() {
 }
 
 start() {
-        [ -f "$PIDFILE".pids ] && stop
+        [ -f "${PIDFILE}.pids" ] && stop
         
        config_load sshtunnel
        if [ -n "$(uci show sshtunnel.@server[0])" ] # at least one server section exists
index 77a8d6fc0189d35cc5c9125fe41917c2448c49b9..0ff18a6a2936044225e15b83426192bcdb202805 100644 (file)
@@ -10,11 +10,12 @@ while true
 do
        logger -p daemon.info -t "sshtunnel[$$][$server]" "connection started"
        
-       start-stop-daemon -S -p "$PIDFILE"_"$$".pid -mx ssh -- $args &>/tmp/log/sshtunnel_$$ 
+       start-stop-daemon -S -p "${PIDFILE}_${$}.pid" -mx ssh -- $args &>/tmp/log/sshtunnel_$$ 
        
        logger -p daemon.err -t "sshtunnel[$$][$server]" < /tmp/log/sshtunnel_$$
        rm /tmp/log/sshtunnel_$$
        logger -p daemon.info -t "sshtunnel[$$][$server]" "ssh exited with code $?, retrying in $retrydelay seconds"
-       
+       rm "${PIDFILE}_${$}.pid"
+
        sleep "$retrydelay" & wait
 done