systemctl
jerabaul29 opened this issue · 0 comments
jerabaul29 commented
pi@raspberrypi:/etc/systemd/system $ cat tunnel.service
[Unit]
Description=Maintain Reverse Tunnel
After=network.target
[Service]
User=pi
ExecStart=/bin/bash /home/pi/Scripts/start_tunnel.sh
RestartSec=15
Restart=always
KillMode=mixed
[Install]
WantedBy=multi-user.target
pi@raspberrypi:~/Scripts $ cat start_tunnel.sh
# exit if a command fails; to circumvent, can add specifically on commands that can fail safely: " || true "
set -o errexit
# make sure to show the error code of the first failing command
set -o pipefail
# do not overwrite files too easily
set -o noclobber
# exit if try to use undefined variable
set -o nounset
# on globbing that has no match, return nothing, rather than return the dubious default ie the pattern itself
# see " help shopt "; use the -u flag to unset (while -s is set)
shopt -s nullglob
sleep 15
eval `ssh-agent`
ssh-add ~/.ssh/id_rsa__nextbox__ssh_forwarding_user_s22a
autossh -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -NR 8080:localhost:22 ssh_forwarding_user_s22a@user-ip -p port