/etc/init.d/autossh_tunnel.foo

Autossh is a nice way to keep a ssh connection alive. This is especially useful when it comes to ssh tunnels. To make things even more automagicial I have now written the init script template autossh_tunnel.foo.

A few import facts regarding the script:

  • Autossh 1.4 or later is required. Earlier versions of autossh doesn’t handle PID-files.
  • The init script is based on the start-stop-daemon. Hence it will probably only work on Debian, Ubuntu and similar systems.
  • There is no way to enter a password. A setup based on ssh-keys or similar is required.
  • Autossh doesn’t handle every kind of ssh problem. Because of that it is possible for the initial connection to fail without the init script knowing about it.

This is by the way my first real init script. Any feedback on it would be greatly appreciated.

3 Responses to /etc/init.d/autossh_tunnel.foo

  1. Anonymous January 14, 2012 at 12:50

    Exactly what I needed, and works flawlessly, thanks!
    Added the tunnel script in /etc/init.d/, “chmod +x tunnel”, and “update-rc.d tunnel defaults” so it starts on reboot.

  2. Anonymous March 2, 2013 at 08:53

    I am running autossh on behalf of a user called deploy. This required the following changes to the script

    d_start() {
    touch $PIDFILE
    chown deploy $PIDFILE
    start-stop-daemon -c deploy –start –quiet –pidfile $PIDFILE \

    • Andreas March 2, 2013 at 09:55

      Good point. In case I get around to rewriting this init script to a more modern init system I’ll make sure to include the option to specify what user to run as. Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.