Last active
December 30, 2015 16:18
-
-
Save mmcdaris/7853362 to your computer and use it in GitHub Desktop.
reboot persistent ssh tunnel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# location: /etc/init/tunnel.conf | |
description "persistent ssh tunnel through reboots" | |
author "morgan mcdaris <[email protected]>" | |
start on (local-filesystems and net-device-up IFACE=eth0) | |
stop on runlevel [016] | |
respawn | |
respawn limit 5 60 | |
script | |
exec su LOCAL_USERNAME -c "ssh -N -R 4040:localhost:22 -i /home/LOCAL_USERNAME/.ssh/id_rsa REMOTE_USERNAME@REMOTE_MACHINE_IP" | |
end script | |
post-start script | |
PID=`status tunnel | egrep -oi '([0-9]+)$' | head -n1` | |
echo $PID > /var/run/tunnel.pid | |
end script | |
post-stop script | |
rm -f /var/run/tunnel.pid | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment