diff --git a/surok.py b/surok.py index 43913f1..545f193 100755 --- a/surok.py +++ b/surok.py @@ -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) diff --git a/surok/system.py b/surok/system.py new file mode 100644 index 0000000..bba454e --- /dev/null +++ b/surok/system.py @@ -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 diff --git a/surok/templates.py b/surok/templates.py index b141839..6fd3363 100644 --- a/surok/templates.py +++ b/surok/templates.py @@ -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)