2016-08-01 15:24:13 +03:00
|
|
|
import os
|
|
|
|
|
2016-08-01 16:09:07 +03:00
|
|
|
|
|
|
|
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')
|
2016-08-01 15:24:13 +03:00
|
|
|
f.write(service_conf)
|
|
|
|
f.close()
|
|
|
|
|
2016-08-01 16:09:07 +03:00
|
|
|
|
|
|
|
def reload_conf(service_conf, app_conf):
|
|
|
|
|
|
|
|
# Check old config
|
2016-08-02 19:02:25 +03:00
|
|
|
if get_old(app_conf['conf_name'], service_conf) != 1:
|
2016-08-01 16:09:07 +03:00
|
|
|
print('Write new configuration')
|
|
|
|
|
|
|
|
f = open(app_conf['dest'], 'w')
|
|
|
|
f.write(service_conf)
|
|
|
|
f.close()
|
|
|
|
|
2016-08-02 19:02:25 +03:00
|
|
|
write_lock(app_conf['conf_name'], service_conf)
|
2016-08-01 16:09:07 +03:00
|
|
|
|
|
|
|
# Reload conf
|
|
|
|
stdout = os.popen(app_conf['reload_cmd']).read()
|
|
|
|
return stdout
|
|
|
|
else:
|
|
|
|
return 'Same config. Skip reload'
|