tunnel, restart the service if the remote host no longer forwards to the local process.
This commit is contained in:
1 parent
1764ca510f
commit
b1bdc953c2
1 file changed
+30
-1
@@ -17,6 +17,20 @@
|
||||
ansible.builtin.set_fact:
|
||||
tunnel_service_name: tunnel
|
||||
|
||||
- name: General | Tunnel | Packages [pacman]
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- openbsd-netcat
|
||||
state: present
|
||||
when: ansible_pkg_mgr == "pacman"
|
||||
|
||||
- name: General | Tunnel | Packages [apt]
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- netcat-openbsd
|
||||
state: present
|
||||
when: ansible_pkg_mgr == "apt"
|
||||
|
||||
- name: General | Tunnel | runit
|
||||
block:
|
||||
|
||||
@@ -38,7 +52,22 @@
|
||||
content: |
|
||||
#!/bin/sh -e
|
||||
exec 2>&1
|
||||
exec chpst -u {{ user }} ssh -v -N \
|
||||
|
||||
# Health check to ensure connection does not go stale.
|
||||
(
|
||||
while true; do
|
||||
sleep 300
|
||||
nc -zv {{ tunnel_remote_host }} {{ tunnel_remote_port }} >/dev/null 2>&1
|
||||
status="$?"
|
||||
if [[ "$status" != 0 ]]; then
|
||||
echo "RUN: Port check returned $status, restarting service."
|
||||
sv restart {{ tunnel_service_name }}
|
||||
fi
|
||||
done
|
||||
) &
|
||||
|
||||
# Do not use `exec` here otherwise the loop may get killed.
|
||||
chpst -u {{ user }} ssh -v -N \
|
||||
-R {{ tunnel_remote_port }}:localhost:{{ tunnel_local_port }} \
|
||||
-p {{ tunnel_ssh_port }} {{ tunnel_remote_host }}
|
||||
mode: "0755"
|
||||
|
||||
Reference in new issue
Block a user