Skip to content

Instantly share code, notes, and snippets.

@Strykar
Last active September 30, 2022 12:07
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Strykar/a65cf6461fdcc41a3e78f5fbbf9e18f9 to your computer and use it in GitHub Desktop.
Save Strykar/a65cf6461fdcc41a3e78f5fbbf9e18f9 to your computer and use it in GitHub Desktop.
[Unit]
Description=AutoSSH service to remotely access signald's unix socket for weechat's signal.py (/smsg +145789323231)
After=network-online.target
# Use this instead if autossh will interact with the local SSH server
# After=network-online.target sshd.service
[Service]
Environment="AUTOSSH_GATETIME=30"
Environment="AUTOSSH_POLL=30"
Environment="AUTOSSH_FIRST_POLL=30"
Environment="SSOCK=/var/run/signald/signald.sock"
# Set aggressive network timeouts not autossh systemd unit timeouts and also avoid Broken pipe errors.
# After 30 seconds of no server response, Autossh will re-negotiate a new session.
# This assumes SSH version >=2. See https://bit.ly/3bINv8v
# Set 'ClientAliveInterval 10' in the remote sshd_config so unresponsive SSH clients will be
# disconnected after approx. (10 x ClientAliveCountMax) = 30 seconds
ExecStart=/usr/bin/autossh -M 0 \
-o "ServerAliveInterval 10" \
-o "ServerAliveCountMax 3" \
-o "StreamLocalBindUnlink yes" \
-o "ExitOnForwardFailure yes" \
-L ${SSOCK}:${SSOCK} -N lair2 #sleep 10
# We set 'sleep 10' to make ssh exit in case no TCP connections are forwarded in 10 seconds.
# Useful to get remote shell exit codes.
ExecStop=/usr/bin/kill $MAINPID
ExecReload=/usr/bin/kill -HUP $MAINPID
Restart=always
# On Linux TCP_TIMEWAIT_LEN is not tunable and set to (60*HZ), about 60 seconds. TCP_FIN_TIMEOUT also defauls to 60 seconds.
RestartSec=60
# See systemd.kill(5)
KillMode=process
[Install]
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment