Mail on Failure

mail-on-failure is a simple post-* hook that sends mails to the user in case the synchronization failed, in the style of fetchmail's messages about authentication failures.

When synchronization fails, $USER receives a mail with the following subject containing the logs of the synchronization:

[smd] sync with $endpoint failed

When a subsequent synchronization attempt is successful, the $USER is notified with the following message:

[smd] sync with $endpoint succeeded

Note that the mail is sent with the mail command, thus local delivery has to be functional.

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