Skip to content

Instantly share code, notes, and snippets.

@tersmitten
Created January 4, 2015 19:34
Show Gist options
  • Save tersmitten/7d32e58c44f24539e606 to your computer and use it in GitHub Desktop.
Save tersmitten/7d32e58c44f24539e606 to your computer and use it in GitHub Desktop.
cat /etc/init/persistent-mysql-tunnel.conf
# persistent-mysql-tunnel
description "Set up a persistent mysql tunnel (using autossh)"
author "Mischa ter Smitten"
start on net-device-up IFACE=eth0
stop on runlevel [01S6]
respawn
respawn limit 5 60 # Respawn max 5 times in 60 seconds
umask 022
pre-start script
test -x /usr/bin/autossh || { stop; exit 0; }
mkdir -p -m0755 /var/run/autossh
end script
script
export AUTOSSH_PIDFILE=/var/run/autossh/persistent-mysql-tunnel.pid
export AUTOSSH_POLL=60
export AUTOSSH_FIRST_POLL=30
export AUTOSSH_GATETIME=0
export AUTOSSH_DEBUG=1
autossh -M 0 -4 -N -L 3307:127.0.0.1:3306 autossh@example.com -p 22 -i /etc/autossh/id_rsa -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -o "BatchMode=yes" -o "StrictHostKeyChecking=no"
end script
@tersmitten
Copy link
Author

Restart the tunnel like this:

restart persistent-mysql-tunnel;

@tersmitten
Copy link
Author

Put this file in /etc/init/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment