Created
January 31, 2024 07:15
-
-
Save epilys/922e3c0b8e608e6830eac3be2f0f7ff9 to your computer and use it in GitHub Desktop.
systemd service to port forward service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Setup a secure tunnel to a local API port on another server named my-other-server in ssh config | |
After=network-online.target | |
[Service] | |
SyslogIdentifier="my-api-tunnel" | |
ExecStartPre=/bin/sh -c "/usr/bin/ssh -O exit my-other-service; true" | |
ExecStop=/bin/sh -c "/usr/bin/ssh -O exit my-other-service; true" | |
ExecStart=/usr/bin/ssh -NT -o LogLevel=ERROR -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -L 8000:localhost:8000 my-other-service | |
# Restart every >2 seconds to avoid StartLimitInterval failure | |
RestartSec=5 | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment