autoconf little work on swarm support
This commit is contained in:
parent
e04c783d1e
commit
781e4c8cbb
|
@ -79,18 +79,24 @@ class Config :
|
|||
return False
|
||||
|
||||
def __reload(self, instances) :
|
||||
# Send SIGHUP to all running instances
|
||||
ret = True
|
||||
for instance_id, instance in instances.items() :
|
||||
# Reload the instance object just in case
|
||||
instance.reload()
|
||||
# Reload via API
|
||||
if self.__swarm :
|
||||
# TODO : send POST requests on http://service-name:8000/reload ?
|
||||
#name = instance.attrs["Spec"]["Attrs"]
|
||||
#req = requests.post("http://" + name + ":8000/reload")
|
||||
#if req and req.status_code == 200 :
|
||||
# utils.log("[*] ")
|
||||
#else :
|
||||
#
|
||||
#pass
|
||||
# Send POST request on http://serviceName.NodeID.TaskID:8000/reload
|
||||
name = instance.name
|
||||
for task in instance.tasks() :
|
||||
nodeID = task["NodeID"]
|
||||
taskID = task["ID"]
|
||||
fqdn = name + "." + nodeID + "." + taskID
|
||||
req = requests.post("http://" + fqdn + ":8000/reload")
|
||||
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" :
|
||||
try :
|
||||
instance.kill("SIGHUP")
|
||||
|
|
|
@ -18,6 +18,9 @@ except Exception as e :
|
|||
# Check if we are in Swarm mode
|
||||
swarm = os.getenv("SWARM_MODE") == "yes"
|
||||
|
||||
# Setup cron tasks if we are in Swarm mode
|
||||
# TODO
|
||||
|
||||
# Our object to process events
|
||||
autoconf = AutoConf(swarm)
|
||||
|
||||
|
|
|
@ -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]
|
||||
with open(file, "w") as f :
|
||||
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", "")
|
||||
|
|
Loading…
Reference in New Issue