summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2017-08-16 16:54:18 +0000
committerMike Crute <mike@crute.us>2017-08-16 16:54:18 +0000
commitf8bdc2eedd1c7b028c900b0af99ee5e68190c082 (patch)
tree2e1dfbd1f69fde1352764877cec9f4931dc60873
parent232681e150432aa962ad8544407a6cf91d149de3 (diff)
downloadserver_bin-f8bdc2eedd1c7b028c900b0af99ee5e68190c082.tar.bz2
server_bin-f8bdc2eedd1c7b028c900b0af99ee5e68190c082.tar.xz
server_bin-f8bdc2eedd1c7b028c900b0af99ee5e68190c082.zip
Add phonehome script
-rwxr-xr-xphonehome.sh52
1 files changed, 52 insertions, 0 deletions
diff --git a/phonehome.sh b/phonehome.sh
new file mode 100755
index 0000000..f469d6c
--- /dev/null
+++ b/phonehome.sh
@@ -0,0 +1,52 @@
1#!/bin/bash
2#
3# Alternate Access Tunnel for Remote Hosts
4#
5# Opens an SSH connection to a central aggregation host and forwards the local
6# SSH port over that connection. This allows remote connections to the server
7# from the central aggregation host. In the absence of true OOB recovery
8# systems this mechanism provides some OOB recovery capability provided the
9# entire internet connection is not down.
10#
11
12KEY=/root/.ssh/phonehome.id_rsa
13CRONTAB=/var/spool/cron/crontabs/root
14CRON_ENTRY="*/5 * * * * /root/phonehome.sh"
15
16# Alt host hedges against DNS being down if the default DNS server is on the
17# wrong side of a collapsed ssh tunnel
18#
19# Grab only answers starting with numbers since we're trying to resolve the IP
20# itself not the hostname (in the absence of normal DNS). Grab the first numeric
21# answer in the case of multiple records
22HOST_IP=$(dig +short @8.8.8.8 phonehome.crute.me | awk '/^[0-9]+/ { print $0; exit; }')
23
24function start_autossh {
25 autossh -f \
26 -gNxCT \
27 -l phonehome -p 4321 $1 \
28 -i $KEY \
29 -R $REMOTE_PORT:localhost:22
30}
31
32if [ ! -f /etc/default/phonehome ]; then
33 echo "echo 'REMOTE_PORT=1234' > /etc/default/phonehome"
34 exit 1
35else
36 source /etc/default/phonehome
37fi
38
39if ! grep 'phonehome.sh' $CRONTAB 2>&1 > /dev/null; then
40 echo "Not in crontab, adding"
41 echo "$CRON_ENTRY" >> $CRONTAB
42else
43 if ! grep -F "$CRON_ENTRY" $CRONTAB 2>&1 > /dev/null; then
44 echo "In crontab but not correct, fixing"
45 sed -i '/phonehome.sh/d' $CRONTAB
46 echo "$CRON_ENTRY" >> $CRONTAB
47 fi
48fi
49
50if ! pgrep autossh > /dev/null; then
51 start_autossh $HOST_IP
52fi