-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstartup.sh
43 lines (35 loc) · 1.09 KB
/
startup.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
#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
cat <<EOF > /usr/local/sbin/health-check-server.py
#!/usr/bin/python
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
import subprocess
PORT_NUMBER = 80
PING_HOST = "www.google.com"
def connectivityCheck():
try:
subprocess.check_call(["ping", "-c", "1", PING_HOST])
return True
except subprocess.CalledProcessError as e:
return False
#This class will handle any incoming request
class myHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/health-check':
if connectivityCheck():
self.send_response(200)
else:
self.send_response(503)
else:
self.send_response(404)
try:
server = HTTPServer(("", PORT_NUMBER), myHandler)
print "Started httpserver on port " , PORT_NUMBER
#Wait forever for incoming http requests
server.serve_forever()
except KeyboardInterrupt:
print "^C received, shutting down the web server"
server.socket.close()
EOF
nohup python /usr/local/sbin/health-check-server.py >/dev/null 2>&1 &