-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_curl_echo_server.sh
56 lines (47 loc) · 1.69 KB
/
set_curl_echo_server.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
function generate_curlechoserver_service() {
# generate the service files
echo
read -rp "What is the echo server hostname (without http:// or https://) > " ECHO_SERVER
if [[ $(curl -w '%{http_code}' https://$ECHO_SERVER/health/ -o /dev/null -s) != "200" ]]; then
echo "unable to reach the echo server at https://$ECHO_SERVER/health/, skip adding curl_echo_server service."
echo
return
fi
echo
ECHO_URL=https://$ECHO_SERVER/echo/
sudo cp "$PWD"/extras/curl_echo_server /usr/local/bin
sudo chmod 755 /usr/local/bin/curl_echo_server
cat > curl_echo_server.service <<EOF
[Unit]
Description=curl the echo server repeatedly to report current server's public ip address
[Service]
User=root
Restart=always
RestartSec=5
WatchdogSec=21600
Nice=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=curl_echo_server
ExecStart=/usr/local/bin/curl_echo_server $ECHO_URL
[Install]
WantedBy=multi-user.target
EOF
sudo chmod 644 curl_echo_server.service
sudo cp curl_echo_server.service /lib/systemd/system/
sudo systemctl enable curl_echo_server
sudo systemctl restart curl_echo_server
}
# check if we should add the curl_echo_server service
echo
echo "The echo server is meant to come up and serving as a reference"
echo " to figure out the IP address of a remote server, in case the"
echo " remote isn't configured to be attached to a domain name and"
echo " its IP address is given by the ISP which can change over time."
echo
echo "If you have setup an echo server using https://github.com/OnTitansShoulder/echo-server"
read -rp " you can proceed [y/N] > " PROCEED
if [[ $PROCEED == "y" || $PROCEED == "Y" ]]; then
generate_curlechoserver_service
fi