1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #!/bin/sh
- #
- # Released under the terms of GPLv3 or at your option any later version.
- # No warranties.
- # Copyright 2008-2010 Enrico Tassi <gares@fettunta.org>
- #
- # lines beginning with a double '#' are considered the documentation
- # of the hook, and should use the markdown syntax
- #
- ## Persistent ssh connection
- ## =========================
- ##
- ## Ssh can share multiple sessions over a single network connection.
- ## This feature allows to speedup connections.
- ##
- ## The `persistent-ssh` script is a `pre-*` hook that
- ## starts (if necessary) a mother connection the first time that
- ## it is needed. To make this hook work properly, you have to
- ## setup ssh as explained in the following.
- ##
- ## Your `.ssh` directory should have permission `700`, and your
- ## `.ssh/config` file should look like this, where `smd-server-foo`
- ## is the `SERVERNAME` specified in your smd config file:
- ##
- ## Host smd-server-foo
- ## ControlPath ~/.ssh/master-socket-%l-%r@%h:%p
- ## ControlMaster auto
- ## PermitLocalCommand yes
- ## LocalCommand ln -sf ~/.ssh/master-socket-%l-%r@%h:%p ~/.ssh/master-socket-smd-server-foo
- ## BatchMode yes
- ## Compression yes
- ## Hostname your.real.server.name
- ## User you
- ##
- ## The key ingredient is to obtain standard name for the master socket of a
- ## given endpoint, in that case `~/.ssh/master-socket-smd-server-foo` for
- ## the endpoint `smd-server-foo`. Refer the `ssh_config` man page for a
- ## detailed explanation of `ControlMaster` and `ControlPath`.
- ##
- ## Note that you may want to put the first four lines also in a more
- ## generic configuration entry, so that every ssh connection to your
- ## server can benefit from connection sharing. For example, a complete
- ## ssh configuration file for `your.real.server.name` may look like
- ## the following:
- ##
- ## Host smd-server-foo
- ## ControlPath ~/.ssh/master-socket-%l-%r@%h:%p
- ## ControlMaster auto
- ## PermitLocalCommand yes
- ## LocalCommand ln -sf ~/.ssh/master-socket-%l-%r@%h:%p ~/.ssh/master-socket-smd-server-foo
- ## BatchMode yes
- ## Compression yes
- ## Hostname your.real.server.name
- ## User you
- ##
- ## Host your.real.server.name
- ## ControlPath ~/.ssh/master-socket-%l-%r@%h:%p
- ## ControlMaster auto
- ## PermitLocalCommand yes
- ## LocalCommand ln -sf ~/.ssh/master-socket-%l-%r@%h:%p ~/.ssh/master-socket-smd-server-foo
-
- when="$1"
- what="$2"
- endpoint="$3"
- status="$4"
-
- SMD_ROOT=$HOME/.smd
-
- . $SMD_ROOT/config.$endpoint
-
- MASTER_SOCKET=~/.ssh/master-socket-$SERVERNAME
-
- # on failure we send the mail, and create HOOK_STATUS
- if [ "$when" = "pre" -a ! -e $MASTER_SOCKET ]; then
- # we spawn ssh and put it in the background
- # so that all subsequent connection attempts
- # reuse the same socket
- set +e
- ssh -fN $SERVERNAME
- set -e
- fi
-
- # vim:set ft=sh:
|