summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@lasker.childrenofmay.org>2023-04-22 17:12:47 -0400
committerroot <root@lasker.childrenofmay.org>2023-04-22 17:12:47 -0400
commit0e5b1be3ea356826c79fbdae01d6233542691176 (patch)
tree5125973c391481195ddb5b31fcf3db52752559a5
parentdc464efdd6c8f3da9892559880e133d630387c31 (diff)
make work
-rwxr-xr-xsocat.sh23
1 files changed, 11 insertions, 12 deletions
diff --git a/socat.sh b/socat.sh
index 9d41445..76ec932 100755
--- a/socat.sh
+++ b/socat.sh
@@ -1,17 +1,9 @@
1#!/bin/bash 1#!/bin/bash
2UNIT=socat-dns 2UNIT=socat-dns
3 3
4DEST=${1:-149.56.44.185}
5PORT=${2:-53}
6LOCAL_PORT=${3:-$PORT}
7
8COMMAND="socat -v UDP-RECVFROM:$LOCAL_PORT,fork UDP-SENDTO:$DEST:$PORT"
9
10verify_service_availability() 4verify_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
17watchdog() 9watchdog()
@@ -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