Compare commits
3 commits
bee1e4a689
...
213abbb14d
Author | SHA1 | Date | |
---|---|---|---|
213abbb14d | |||
5fe61b6a41 | |||
7c195841cd |
2 changed files with 6 additions and 6 deletions
|
@ -1 +0,0 @@
|
||||||
python-daemon==3.0.1
|
|
11
src/main.py
11
src/main.py
|
@ -1,5 +1,4 @@
|
||||||
import http.client
|
import http.client
|
||||||
import daemon
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
@ -31,12 +30,18 @@ def reachable(domain: str) -> tuple[bool, str]:
|
||||||
return False, e.__str__()
|
return False, e.__str__()
|
||||||
|
|
||||||
def monitor():
|
def monitor():
|
||||||
|
last_was_fail: bool = False
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
b, msg = check_net()
|
b, msg = check_net()
|
||||||
if not b:
|
if not b:
|
||||||
print(f":FAILURE AT {datetime.now()}:")
|
print(f":FAILURE AT {datetime.now()}:")
|
||||||
print(msg)
|
print(msg)
|
||||||
|
last_was_fail = True
|
||||||
|
elif b and last_was_fail:
|
||||||
|
print(f":SUCCESS AT {datetime.now()}:")
|
||||||
|
print(msg)
|
||||||
|
last_was_fail = False
|
||||||
sleep(SLEEPTIME)
|
sleep(SLEEPTIME)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
@ -44,7 +49,3 @@ def monitor():
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("executing as normal script")
|
print("executing as normal script")
|
||||||
monitor()
|
monitor()
|
||||||
|
|
||||||
with daemon.DaemonContext():
|
|
||||||
print("entering daemon mode")
|
|
||||||
monitor()
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue