[ -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)"
}
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
}
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
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