Create systemd units

  1. create a <UNIT>.service file and copy to /etc/systemd/system/<UNIT>.service
  2. grab template content from beneath
  3. run sudo systemctl daemon-reload to indicate that new units have been created
  4. check if unit is listed with sudo systemctl list-unit-files
  5. start service with sudo systemctl start <UNIT>
  6. check status of unit with sudo systemctl status <UNIT>
  7. enable service with sudo systemctl enable <UNIT> to start at boot

systemd unit template

[Unit]
Description=Service for making reverse autossh connections for OpenVPN usage
After=network-online.target
 
[Install]
WantedBy=multi-user.target
 
[Service]
Environment="AUTOSSH_GATETIME=30"
Environment="AUTOSSH_POLL=30"
Environment="AUTOSSH_FIRST_POLL=30"
 
Type=simple
ExecStart=/usr/bin/autossh -M 0 \
-q -gNC -f \
-o "ServerAliveInterval=60" \
-o "ServerAliveCountMax=4" \
-o "ExitOnForwardFailure=yes" \
-R 1194:192.168.1.15:2343 root@ionos.vps
 
ExecStop=/usr/bin/kill $MAINPID
ExecReload=/usr/bin/kill -HUP $MAINPID
 
Restart=always
RestartSec=60
 
KillMode=process