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