Config reload
This commit is contained in:
parent
f6a48f9bd3
commit
472bf1c2c4
9
surok.py
9
surok.py
@ -6,6 +6,7 @@ from os.path import isfile, join
|
|||||||
import json
|
import json
|
||||||
from surok.templates import gen
|
from surok.templates import gen
|
||||||
from surok.discovery import resolve
|
from surok.discovery import resolve
|
||||||
|
from surok.system import reload_conf
|
||||||
|
|
||||||
# Load base configurations
|
# Load base configurations
|
||||||
f = open('conf/surok.json', 'r')
|
f = open('conf/surok.json', 'r')
|
||||||
@ -32,12 +33,14 @@ def load_app_conf(app):
|
|||||||
# Main loop
|
# Main loop
|
||||||
while 1:
|
while 1:
|
||||||
confs = get_configs()
|
confs = get_configs()
|
||||||
|
|
||||||
for app in confs:
|
for app in confs:
|
||||||
app_conf = load_app_conf(app)
|
app_conf = load_app_conf(app)
|
||||||
app_hosts = resolve(app_conf, conf)
|
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)
|
sleep(5)
|
||||||
|
|
||||||
|
10
surok/system.py
Normal file
10
surok/system.py
Normal 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
|
@ -3,10 +3,10 @@ from jinja2 import Environment, PackageLoader, Template
|
|||||||
|
|
||||||
# Return rendered configuration
|
# Return rendered configuration
|
||||||
def gen(my, jj2):
|
def gen(my, jj2):
|
||||||
f = open(jj2)
|
f = open(jj2, 'r')
|
||||||
temp = f.read()
|
temp = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
template = Template(temp)
|
template = Template(temp)
|
||||||
|
|
||||||
print( template.render(my=my) )
|
return template.render(my=my)
|
||||||
|
Loading…
Reference in New Issue
Block a user