autoconf little work on swarm support

This commit is contained in:
bunkerity 2021-03-10 17:24:02 +01:00
parent e04c783d1e
commit 781e4c8cbb
3 changed files with 29 additions and 9 deletions

View File

@ -79,18 +79,24 @@ class Config :
return False return False
def __reload(self, instances) : def __reload(self, instances) :
# Send SIGHUP to all running instances
ret = True ret = True
for instance_id, instance in instances.items() : for instance_id, instance in instances.items() :
# Reload the instance object just in case
instance.reload()
# Reload via API
if self.__swarm : if self.__swarm :
# TODO : send POST requests on http://service-name:8000/reload ? # Send POST request on http://serviceName.NodeID.TaskID:8000/reload
#name = instance.attrs["Spec"]["Attrs"] name = instance.name
#req = requests.post("http://" + name + ":8000/reload") for task in instance.tasks() :
#if req and req.status_code == 200 : nodeID = task["NodeID"]
# utils.log("[*] ") taskID = task["ID"]
#else : fqdn = name + "." + nodeID + "." + taskID
# req = requests.post("http://" + fqdn + ":8000/reload")
#pass if req and req.status_code == 200 :
utils.log("[*] Sent reload order to instance " + fqdn + " (service.node.task)")
else :
utils.log("[!] Can't reload : API error for instance " + fqdn + " (service.node.task)")
# Send SIGHUP to running instance
elif instance.status == "running" : elif instance.status == "running" :
try : try :
instance.kill("SIGHUP") instance.kill("SIGHUP")

View File

@ -18,6 +18,9 @@ except Exception as e :
# Check if we are in Swarm mode # Check if we are in Swarm mode
swarm = os.getenv("SWARM_MODE") == "yes" swarm = os.getenv("SWARM_MODE") == "yes"
# Setup cron tasks if we are in Swarm mode
# TODO
# Our object to process events # Our object to process events
autoconf = AutoConf(swarm) autoconf = AutoConf(swarm)

View File

@ -11,3 +11,14 @@ def replace_in_file(file, old_str, new_str) :
data = data[::-1].replace(old_str[::-1], new_str[::-1], 1)[::-1] data = data[::-1].replace(old_str[::-1], new_str[::-1], 1)[::-1]
with open(file, "w") as f : with open(file, "w") as f :
f.write(data) f.write(data)
def install_cron(service, vars, crons) :
for var in vars :
if var in crons :
with open("/etc/crontabs/root", "a+") as f :
f.write(vars[var] + " /opt/cron/" + crons[var] + ".py " + service["Actor"]["ID"])
def uninstall_cron(service, vars, crons) :
for var in vars :
if var in crons :
replace_in_file("/etc/crontabs/root", vars[var] + " /opt/cron/" + crons[var] + ".py " + service["Actor"]["ID"] + "\n", "")