Skip to content

Instantly share code, notes, and snippets.

@mmcdaris
Last active December 30, 2015 16:18
Show Gist options
  • Save mmcdaris/7853362 to your computer and use it in GitHub Desktop.
Save mmcdaris/7853362 to your computer and use it in GitHub Desktop.
reboot persistent ssh tunnel
# 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