Skip to content

Instantly share code, notes, and snippets.

@wolfg1969
Created September 6, 2012 07:05
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfg1969/3652371 to your computer and use it in GitHub Desktop.
Save wolfg1969/3652371 to your computer and use it in GitHub Desktop.
autossh upstart conf
# tunnel - secure tunnel to my vps
description "ssh tunnel"
start on (local-filesystems and network-device-up IFACE!=lo)
stop on runlevel [!12345]
respawn
respawn limit 5 60 # respawn max 5 times in 60 seconds
umask 022
script
echo "DEBUG: `set`" >> /tmp/tunnel.log
export AUTOSSH_PIDFILE=/var/run/tunnel.pid
export AUTOSSH_PORT=10007:7
export AUTOSSH_POLL=60
export AUTOSSH_FIRST_POLL=30
exec sudo -H -u user -s autossh -4 -N -D 3128 -o BatchMode=yes -o StrictHostKeyChecking=no -i /home/user/.ssh/tunnel_id_rsa user@host
end script
Copy link

ghost commented Feb 2, 2014

Thanks for sharing your upstart script!
Three comments:

  • The start on stanza didn't work for me on ubuntu 13.10. Using start on net-device-up did the trick for me.
  • add the -E option to sudo to preserve the environment variables you just exported.
  • When you've tested your autossh connection, I'd suggest to add the AUTOSSH_GATETIME environment variable and set it to 0 to make autossh ignore the first run failure of ssh (in case the remote host is down when autossh starts).

Bests,

Bram

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