-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreload.py
More file actions
73 lines (62 loc) · 2.44 KB
/
reload.py
File metadata and controls
73 lines (62 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from taskmaster import *
class reload:
def __init__(self, procs):
self.procs = procs
self.reload_config()
def replace(self, item, param):
item.name = param.name
item.cmd = param.cmd
item.numprocs = param.numprocs
item.autostart = param.autostart
item.autorestart = param.autorestart
item.starttime = param.starttime
item.stoptime = param.stoptime
item.restartretries = param.restartretries
item.stopsig = param.stopsig
item.exitcodes = param.exitcodes
item.workingdir = param.workingdir
item.umask = param.umask
item.stdout = param.stdout
item.stderr = param.stderr
item.env = param.env
item.proc = param.proc
item.status = param.status
item.checked = param.checked
item._hash = param._hash
item.pid = param.pid
item.exitcode = param.exitcode
def hash_it(self, item):
return (
str(item.name)+str(item.cmd)+str(item.numprocs)+str(item.autostart)+str(item.autorestart)+str(item.starttime)
+str(item.stoptime) + str(item.restartretries)+str(item.stopsig)+str(item.exitcodes)+str(item.workingdir)+str(item.umask)
+str(item.stdout)+str(item.env))
def stop_process(self, proc):
if proc.status == "STARTED" or proc.status == "RUNNING":
os.kill(proc.pid, proc.stopsig)
if proc.thread != None:
proc.thread.cancel()
def reload_config(self):
cfile = pre_execution(parse("config.json"))
j = 1
for i in range(0, len(cfile.config_class)):
cfile.config_class[i].name += "_" + str(j)
if j == cfile.config_class[i].numprocs:
j = 1
else:
j += 1
found = 0
for item in cfile.config_class:
found = 0
for proc in self.procs:
if proc.name == item.name and proc._hash == item._hash:
self.replace(item, proc)
found = 1
elif proc.name == item.name and proc._hash != item._hash:
self.stop_process(proc)
found = 1
execution(item, "execute")
if found == 0:
execution(item, "execute")
del self.procs[:]
for item in cfile.config_class:
self.procs.append(item)