Merge pull request #33 from markormesher/feat/handle-sigterm
handle sigterm and shutdown immediately
This commit is contained in:
commit
6140917119
@ -1,4 +1,4 @@
|
|||||||
import requests, json, sys, os
|
import requests, json, sys, signal, os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
PATH = os.getcwd() + "/"
|
PATH = os.getcwd() + "/"
|
||||||
@ -7,6 +7,12 @@ version = float(str(sys.version_info[0]) + "." + str(sys.version_info[1]))
|
|||||||
if(version < 3.5):
|
if(version < 3.5):
|
||||||
raise Exception("This script requires Python 3.5+")
|
raise Exception("This script requires Python 3.5+")
|
||||||
|
|
||||||
|
def sigtermHandler(sig_no, stack_frame):
|
||||||
|
print("Caught SIGTERM, shutting down...")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGTERM, sigtermHandler)
|
||||||
|
|
||||||
with open(PATH + "config.json") as config_file:
|
with open(PATH + "config.json") as config_file:
|
||||||
config = json.loads(config_file.read())
|
config = json.loads(config_file.read())
|
||||||
|
|
||||||
@ -126,17 +132,20 @@ def updateIPs():
|
|||||||
for ip in getIPs():
|
for ip in getIPs():
|
||||||
commitRecord(ip)
|
commitRecord(ip)
|
||||||
|
|
||||||
if(len(sys.argv) > 1):
|
try:
|
||||||
if(sys.argv[1] == "--repeat"):
|
if(len(sys.argv) > 1):
|
||||||
print("Updating A & AAAA records every 10 minutes")
|
if(sys.argv[1] == "--repeat"):
|
||||||
updateIPs()
|
print("Updating A & AAAA records every 10 minutes")
|
||||||
delay = 10*60 # 10 minutes
|
|
||||||
next_time = time.time() + delay
|
|
||||||
while True:
|
|
||||||
time.sleep(max(0, next_time - time.time()))
|
|
||||||
updateIPs()
|
updateIPs()
|
||||||
next_time += (time.time() - next_time) // delay * delay + delay
|
delay = 10*60 # 10 minutes
|
||||||
|
next_time = time.time() + delay
|
||||||
|
while True:
|
||||||
|
time.sleep(max(0, next_time - time.time()))
|
||||||
|
updateIPs()
|
||||||
|
next_time += (time.time() - next_time) // delay * delay + delay
|
||||||
|
else:
|
||||||
|
print("Unrecognized parameter '" + sys.argv[1] + "'. Stopping now.")
|
||||||
else:
|
else:
|
||||||
print("Unrecognized parameter '" + sys.argv[1] + "'. Stopping now.")
|
updateIPs()
|
||||||
else:
|
except SystemExit:
|
||||||
updateIPs()
|
print("Goodbye!")
|
||||||
|
|||||||
Reference in New Issue
Block a user