* 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
first = True
while 1:
confs = get_configs()
for app in confs:
@ -55,7 +56,8 @@ while 1:
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'] )

View File

@ -25,20 +25,30 @@ def write_lock(name, service_conf):
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'] )
f = open(app_conf['dest'], 'w')
f.write(service_conf)
f.close()
write_lock(app_conf['conf_name'], service_conf)
# Reload conf
stdout = os.popen(app_conf['reload_cmd']).read()
return stdout
def reload_conf(service_conf, app_conf, first):
# Check old config
# 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:
print('Write new configuration')
f = open(app_conf['dest'], 'w')
f.write(service_conf)
f.close()
write_lock(app_conf['conf_name'], service_conf)
# Reload conf
stdout = os.popen(app_conf['reload_cmd']).read()
return stdout
stdout = do_reload(service_conf, app_conf)
return stdout, first
else:
return 'Same config. Skip reload'
return 'Same config ' + app_conf['conf_name'] + ' Skip reload', first