-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathserver_check.py
More file actions
35 lines (30 loc) · 1.07 KB
/
server_check.py
File metadata and controls
35 lines (30 loc) · 1.07 KB
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
import requests
import time
hub_name = "inouyehub5"
site = "http://%s.localtunnel.me" % hub_name
open_hub = """x-terminal-emulator -e 'bash -c "lt --port 3000 --subdomain %s"'""" % hub_name
def check():
print('trying check')
try:
r = requests.head(site)
if r.status_code != 200:
import subprocess
import shlex
process1 = subprocess.Popen(shlex.split("""x-terminal-emulator -e 'bash -c "node /home/pi/Desktop/rpi_automation/app.js"'"""), stdout=subprocess.PIPE)
def pross2():
v = requests.head("http://inouyehub5.localtunnel.me")
print (v.status_code)
if v.status_code != 200:
process2 = subprocess.Popen(shlex.split(open_hub), stdout=subprocess.PIPE)
time.sleep(2)
z = requests.head("http://inouyehub5.localtunnel.me")
print (z.status_code)
if z.status_code != 200:
pross2()
pross2()
except requests.ConnectionError:
print("failed to connect")
x=1
while x > 0:
check()
time.sleep(30)