From 65552f3d26db9b2bcc0d131ddf69985670436f81 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 24 Apr 2015 23:51:33 +0200 Subject: autotunnel: Adding example config, systemd service file and script for autossh managed SSH tunnel to predefined host --- config/autotunnel/example.conf | 9 +++++++++ scripts/autotunnel | 21 +++++++++++++++++++++ system/autotunnel@.service | 11 +++++++++++ 3 files changed, 41 insertions(+) create mode 100644 config/autotunnel/example.conf create mode 100755 scripts/autotunnel create mode 100644 system/autotunnel@.service diff --git a/config/autotunnel/example.conf b/config/autotunnel/example.conf new file mode 100644 index 0000000..3a348b4 --- /dev/null +++ b/config/autotunnel/example.conf @@ -0,0 +1,9 @@ +# Configuration file for autotunnel + +# Define a host to connect to +# Must be resolvable or better even set up in /root/.ssh/config +HOST= + +# Define a tun device number to use +# Make sure the same device is not used elsewhere on localhost and the machine to connect to! +TUN_DEVICE= diff --git a/scripts/autotunnel b/scripts/autotunnel new file mode 100755 index 0000000..230940d --- /dev/null +++ b/scripts/autotunnel @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +if [ -z "$SERVER_ALIVE_INTERVAL" ];then + SERVER_ALIVE_INTERVAL=45 +fi + +if [ -z "$SERVER_ALIVE_COUNT_MAX" ];then + SERVER_ALIVE_INTERVAL=2 +fi + +if [ -z "$MONITORING_PORT" ];then + MONITORING_PORT=0 +fi + +/usr/bin/autossh -M "$MONITORING_PORT" \ + -NCTv \ + -o ServerAliveInterval="$SERVER_ALIVE_INTERVAL" \ + -o ServerAliveCountMax="$SERVER_ALIVE_COUNT_MAX" \ + -o TCPKeepAlive=yes \ + -w $TUN_DEVICE:$TUN_DEVICE \ + $HOST diff --git a/system/autotunnel@.service b/system/autotunnel@.service new file mode 100644 index 0000000..b128cac --- /dev/null +++ b/system/autotunnel@.service @@ -0,0 +1,11 @@ +[Unit] +Description=AutoSSH managed SSH tunnel to predefined host +After=network.target + +[Service] +Environment="AUTOSSH_GATETIME=0" +EnvironmentFile=/etc/autotunnel/%I.conf +ExecStart=/usr/lib/systemd/scripts/tunnel-to-host + +[Install] +WantedBy=multi-user.target -- cgit v1.2.3-70-g09d2 From c67e1141dedda5108d1330f59038b55ff8829525 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 25 Apr 2015 00:10:56 +0200 Subject: system/autotunnel@.service: Fixing script name. --- system/autotunnel@.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/autotunnel@.service b/system/autotunnel@.service index b128cac..405a7d7 100644 --- a/system/autotunnel@.service +++ b/system/autotunnel@.service @@ -5,7 +5,7 @@ After=network.target [Service] Environment="AUTOSSH_GATETIME=0" EnvironmentFile=/etc/autotunnel/%I.conf -ExecStart=/usr/lib/systemd/scripts/tunnel-to-host +ExecStart=/usr/lib/systemd/scripts/autotunnel [Install] WantedBy=multi-user.target -- cgit v1.2.3-70-g09d2 From cae71ea147acd1a6a7751ad9c2a0a6e3f7f9e651 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 25 Apr 2015 00:15:42 +0200 Subject: scripts/autotunnel: Fixing SERVER_ALIVE_COUNT_MAX --- scripts/autotunnel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/autotunnel b/scripts/autotunnel index 230940d..2a1f17b 100755 --- a/scripts/autotunnel +++ b/scripts/autotunnel @@ -5,7 +5,7 @@ if [ -z "$SERVER_ALIVE_INTERVAL" ];then fi if [ -z "$SERVER_ALIVE_COUNT_MAX" ];then - SERVER_ALIVE_INTERVAL=2 + SERVER_ALIVE_COUNT_MAX=2 fi if [ -z "$MONITORING_PORT" ];then -- cgit v1.2.3-70-g09d2