* Detect new run

* More information in stdout
This commit is contained in:
Difrex 2016-08-04 11:34:02 +03:00
parent b5de8381f6
commit 4c8acc6bc8
2 changed files with 27 additions and 15 deletions

View File

@ -42,6 +42,7 @@ def load_app_conf(app):
# Main loop # Main loop
first = True
while 1: while 1:
confs = get_configs() confs = get_configs()
for app in confs: for app in confs:
@ -55,7 +56,8 @@ while 1:
service_conf = gen(my, app_conf['template']) service_conf = gen(my, app_conf['template'])
print( reload_conf(service_conf, app_conf) ) stdout, first = reload_conf(service_conf, app_conf, first)
print(stdout)
sleep( conf['wait_time'] ) sleep( conf['wait_time'] )

View File

@ -25,11 +25,8 @@ def write_lock(name, service_conf):
f.close() f.close()
def reload_conf(service_conf, app_conf): def do_reload(service_conf, app_conf):
print( 'Write new configuration of ' + app_conf['conf_name'] )
# Check old config
if get_old(app_conf['conf_name'], service_conf) != 1:
print('Write new configuration')
f = open(app_conf['dest'], 'w') f = open(app_conf['dest'], 'w')
f.write(service_conf) f.write(service_conf)
@ -40,5 +37,18 @@ def reload_conf(service_conf, app_conf):
# Reload conf # Reload conf
stdout = os.popen(app_conf['reload_cmd']).read() stdout = os.popen(app_conf['reload_cmd']).read()
return stdout return stdout
def reload_conf(service_conf, app_conf, first):
# Check first loop
if first == True:
stdout = do_reload(service_conf, app_conf)
first = False
return stdout, first
if get_old(app_conf['conf_name'], service_conf) != 1:
stdout = do_reload(service_conf, app_conf)
return stdout, first
else: else:
return 'Same config. Skip reload' return 'Same config ' + app_conf['conf_name'] + ' Skip reload', first