Reload if config is changed
This commit is contained in:
parent
564e851f66
commit
dda33a2eb5
4
surok.py
4
surok.py
@ -39,8 +39,8 @@ while 1:
|
||||
my = {'app': app_conf['name'], 'hosts': app_hosts}
|
||||
service_conf = gen(my, app_conf['template'])
|
||||
|
||||
reload_conf(service_conf, app_conf)
|
||||
print(reload_conf(service_conf, app_conf))
|
||||
|
||||
|
||||
sleep(5)
|
||||
sleep(conf['wait_time'])
|
||||
|
||||
|
@ -1,10 +1,44 @@
|
||||
import os
|
||||
|
||||
def reload_conf(service_conf, app_conf):
|
||||
f = open(app_conf['dest'], 'w')
|
||||
|
||||
def get_old(name, service_conf):
|
||||
|
||||
try:
|
||||
path = '/var/tmp/surok.' + name
|
||||
f = open(path, 'r')
|
||||
old = f.read()
|
||||
f.close()
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return 0
|
||||
|
||||
if old == service_conf:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
def write_lock(name, service_conf):
|
||||
path = '/var/tmp/surok.' + name
|
||||
f = open(path, 'w')
|
||||
f.write(service_conf)
|
||||
f.close()
|
||||
|
||||
# Reload conf
|
||||
stdout = os.popopen(app_conf['reload_cmd']).read()
|
||||
return stdout
|
||||
|
||||
def reload_conf(service_conf, app_conf):
|
||||
|
||||
# Check old config
|
||||
if get_old(app_conf['name'], service_conf) != 1:
|
||||
print('Write new configuration')
|
||||
|
||||
f = open(app_conf['dest'], 'w')
|
||||
f.write(service_conf)
|
||||
f.close()
|
||||
|
||||
write_lock(app_conf['name'], service_conf)
|
||||
|
||||
# Reload conf
|
||||
stdout = os.popen(app_conf['reload_cmd']).read()
|
||||
return stdout
|
||||
else:
|
||||
return 'Same config. Skip reload'
|
||||
|
Loading…
Reference in New Issue
Block a user