diff options
author | root <root@lasker.childrenofmay.org> | 2023-04-22 17:12:47 -0400 |
---|---|---|
committer | root <root@lasker.childrenofmay.org> | 2023-04-22 17:12:47 -0400 |
commit | 0e5b1be3ea356826c79fbdae01d6233542691176 (patch) | |
tree | 5125973c391481195ddb5b31fcf3db52752559a5 | |
parent | dc464efdd6c8f3da9892559880e133d630387c31 (diff) |
make work
-rwxr-xr-x | socat.sh | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -1,17 +1,9 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | UNIT=socat-dns | 2 | UNIT=socat-dns |
3 | 3 | ||
4 | DEST=${1:-149.56.44.185} | ||
5 | PORT=${2:-53} | ||
6 | LOCAL_PORT=${3:-$PORT} | ||
7 | |||
8 | COMMAND="socat -v UDP-RECVFROM:$LOCAL_PORT,fork UDP-SENDTO:$DEST:$PORT" | ||
9 | |||
10 | verify_service_availability() | 4 | verify_service_availability() |
11 | { | 5 | { |
12 | true | 6 | dig . @127.0.0.1 >/dev/null 2>&1 |
13 | return | ||
14 | dig . @localhost | ||
15 | } | 7 | } |
16 | 8 | ||
17 | watchdog() | 9 | watchdog() |
@@ -30,6 +22,11 @@ main() | |||
30 | { | 22 | { |
31 | case "$1" in | 23 | case "$1" in |
32 | install) | 24 | install) |
25 | shift | ||
26 | DEST=${1:-149.56.44.185} | ||
27 | PORT=${2:-53} | ||
28 | LOCAL_PORT=${3:-$PORT} | ||
29 | COMMAND="socat UDP-RECVFROM:$LOCAL_PORT,fork UDP-SENDTO:$DEST:$PORT" | ||
33 | if systemctl is-active "$UNIT" >/dev/null | 30 | if systemctl is-active "$UNIT" >/dev/null |
34 | then | 31 | then |
35 | systemctl stop "$UNIT" | 32 | systemctl stop "$UNIT" |
@@ -38,17 +35,19 @@ main() | |||
38 | 35 | ||
39 | systemd-run \ | 36 | systemd-run \ |
40 | --unit "$UNIT" \ | 37 | --unit "$UNIT" \ |
41 | --property Restart="on-failure" \ | 38 | --property Restart="always" \ |
42 | --property WatchdogSec="5" \ | 39 | --property WatchdogSec="5" \ |
43 | -- \ | 40 | -- \ |
44 | "$0" watchdog | 41 | "$0" watchdog "$COMMAND" |
45 | ;; | 42 | ;; |
46 | watchdog) | 43 | watchdog) |
44 | shift | ||
45 | COMMAND="$1" | ||
47 | watchdog $$ & | 46 | watchdog $$ & |
48 | exec $COMMAND | 47 | exec $COMMAND |
49 | ;; | 48 | ;; |
50 | *) | 49 | *) |
51 | echo "Usage: $0 <watchdog|install>" >&2 | 50 | echo "Usage: $0 install [destination] [destination port] [local port]" >&2 |
52 | exit 1 | 51 | exit 1 |
53 | ;; | 52 | ;; |
54 | esac | 53 | esac |