aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--files/autossh.init.d98
-rw-r--r--manifests/autossh.pp34
2 files changed, 132 insertions, 0 deletions
diff --git a/files/autossh.init.d b/files/autossh.init.d
new file mode 100644
index 0000000..fb3c57f
--- /dev/null
+++ b/files/autossh.init.d
@@ -0,0 +1,98 @@
+#! /bin/sh
+
+### BEGIN INIT INFO
+# Provides: autossh
+# Required-Start: $remote_fs $syslog $network
+# Required-Stop: $remote_fs $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop:
+# Short-Description: Autossh for isuma
+### END INIT INFO
+
+set -e
+
+umask 022
+
+if test -f /etc/default/isuma-autossh; then
+ . /etc/default/isuma-autossh
+fi
+
+. /lib/lsb/init-functions
+
+export PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+case "$1" in
+ start)
+ log_daemon_msg "Starting Autossh for isuma" "autossh"
+ if start-stop-daemon --quiet --start --background --pidfile /var/run/autossh-isuma.pid --make-pidfile --exec /usr/bin/autossh -- $AUTOSSH_ISUMA_OPTS; then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+ ;;
+ stop)
+ log_daemon_msg "Stopping Autossh for isuma" "autossh"
+ if start-stop-daemon --stop --quiet --pidfile /var/run/autossh-isuma.pid ; then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+ ;;
+
+ reload|force-reload)
+ log_daemon_msg "Reloading Autossh for isuma's configuration" "autossh"
+ if start-stop-daemon --stop --signal 1 --quiet --oknodo --pidfile /var/run/autossh-isuma.pid; then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+ ;;
+
+ restart)
+ log_daemon_msg "Restarting Autossh for isuma" "autossh"
+ start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile /var/run/autossh-isuma.pid
+ if start-stop-daemon --start --quiet -b --make-pidfile --pidfile /var/run/autossh-isuma.pid --exec /usr/bin/autossh -- $AUTOSSH_ISUMA_OPTS; then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+ ;;
+
+ try-restart)
+ log_daemon_msg "Restarting Autossh for isuma" "autossh"
+ set +e
+ start-stop-daemon --stop --quiet --retry 30 --pidfile /var/run/autossh-isuma.pid
+ RET="$?"
+ set -e
+ case $RET in
+ 0)
+ # old daemon stopped
+ if start-stop-daemon --start --quiet --oknodo -b --pidfile /var/run/autossh-isuma.pid --make-pidfile --exec /usr/bin/autossh -- $AUTOSSH_ISUMA_OPTS; then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+ ;;
+ 1)
+ # daemon not running
+ log_progress_msg "(not running)"
+ log_end_msg 0
+ ;;
+ *)
+ # failed to stop
+ log_progress_msg "(failed to stop)"
+ log_end_msg 1
+ ;;
+ esac
+ ;;
+
+ status)
+ status_of_proc -p /var/run/autossh-isuma.pid /usr/sbin/autossh autossh && exit 0 || exit $?
+ ;;
+
+ *)
+ log_action_msg "Usage: /etc/init.d/isuma-autossh {start|stop|reload|force-reload|restart|try-restart|status}"
+ exit 1
+esac
+
+exit 0
diff --git a/manifests/autossh.pp b/manifests/autossh.pp
new file mode 100644
index 0000000..80d571b
--- /dev/null
+++ b/manifests/autossh.pp
@@ -0,0 +1,34 @@
+class sshd::autossh($host,
+ $port = undef, # this should be a remote->local hash
+ $remote_user = undef,
+) {
+ if $port {
+ $port_ensure = $port
+ }
+ else {
+ # random port between 10000 and 20000
+ $port_ensure = fqdn_rand(10000) + 10000
+ }
+ if $remote_user {
+ $remote_user_ensure = $remote_user
+ }
+ else {
+ $remote_user_ensure = "host-$fqdn"
+ }
+ file {
+ '/etc/init.d/autossh':
+ mode => '0555',
+ source => 'puppet:///modules/sshd/autossh.init.d';
+ '/etc/default/autossh':
+ mode => '0444',
+ content => "DAEMON_OPTS='-o ServerAliveInterval=15 -o ServerAliveCountMax=4 -q -N -R $port_ensure:localhost:22 $user_ensure@$host'\n";
+ }
+ service { 'autossh':
+ ensure => running,
+ enable => true,
+ subscribe => [
+ File['/etc/init.d/autossh'],
+ File['/etc/default/autossh']
+ ],
+ }
+}