Config reload

This commit is contained in:
Difrex 2016-08-01 15:24:13 +03:00
parent f6a48f9bd3
commit 472bf1c2c4
3 changed files with 18 additions and 5 deletions

View File

@ -6,6 +6,7 @@ from os.path import isfile, join
import json
from surok.templates import gen
from surok.discovery import resolve
from surok.system import reload_conf
# Load base configurations
f = open('conf/surok.json', 'r')
@ -32,12 +33,14 @@ def load_app_conf(app):
# Main loop
while 1:
confs = get_configs()
for app in confs:
app_conf = load_app_conf(app)
app_hosts = resolve(app_conf, conf)
print(app_hosts)
my = {'app': app_conf['name'], 'hosts': app_hosts}
service_conf = gen(my, app_conf['template'])
reload_conf(service_conf, app_conf)
# gen()
sleep(5)

10
surok/system.py Normal file
View File

@ -0,0 +1,10 @@
import os
def reload_conf(service_conf, app_conf):
f = open(app_conf['dest'], 'w')
f.write(service_conf)
f.close()
# Reload conf
stdout = os.popopen(app_conf['reload_cmd']).read()
return stdout

View File

@ -3,10 +3,10 @@ from jinja2 import Environment, PackageLoader, Template
# Return rendered configuration
def gen(my, jj2):
f = open(jj2)
f = open(jj2, 'r')
temp = f.read()
f.close()
template = Template(temp)
print( template.render(my=my) )
return template.render(my=my)