From 4c8acc6bc8646549e93f5a82e2b6be0daa696d10 Mon Sep 17 00:00:00 2001 From: Difrex Date: Thu, 4 Aug 2016 11:34:02 +0300 Subject: [PATCH] * Detect new run * More information in stdout --- surok.py | 4 +++- surok/system.py | 38 ++++++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/surok.py b/surok.py index 6a655a3..9d36561 100755 --- a/surok.py +++ b/surok.py @@ -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'] ) diff --git a/surok/system.py b/surok/system.py index bd1bb7e..87ca63c 100644 --- a/surok/system.py +++ b/surok/system.py @@ -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