Created
November 28, 2013 05:50
-
-
Save jsgarvin/7687773 to your computer and use it in GitHub Desktop.
Automatically establish ssh tunnel to remote postgresql db server on boot, and auto re-establish if connection is lost (eg reboot of remote machine or network failure). Requires autossh.
This file contains hidden or 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
# Modified version of technique borrowed from | |
# http://theantway.com/2012/08/how-to-create-ssh-tunnel-at-boot-time-under-ubuntu/ | |
# Place in /etc/init/ | |
# autossh | |
description "autossh daemon" | |
start on net-device-up IFACE=eth1 | |
stop on runlevel [01S6] | |
respawn | |
respawn limit 5 60 # respawn max 5 times in 60 seconds | |
script | |
export AUTOSSH_PIDFILE=/var/run/autossh.pid | |
export AUTOSSH_POLL=60 | |
export AUTOSSH_FIRST_POLL=30 | |
export AUTOSSH_GATETIME=0 | |
export AUTOSSH_DEBUG=1 | |
autossh -M 0 -2 -N -L 5432:localhost:5432 [email protected] -p REMOTE_PORT -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -o BatchMode=yes -o StrictHostKeyChecking=no -i /path/to/.ssh/id_rsa | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
autossh on systemd
https://gist.github.com/thomasfr/9707568