diff --git a/surok.py b/surok.py index 545f193..31d1585 100755 --- a/surok.py +++ b/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']) diff --git a/surok/system.py b/surok/system.py index bba454e..686fca8 100644 --- a/surok/system.py +++ b/surok/system.py @@ -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'