2016-08-01 12:54:48 +03:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
from time import sleep
|
|
|
|
from os import listdir
|
|
|
|
from os.path import isfile, join
|
|
|
|
import json
|
2016-08-01 14:56:35 +03:00
|
|
|
from surok.templates import gen
|
|
|
|
from surok.discovery import resolve
|
2016-08-01 15:24:13 +03:00
|
|
|
from surok.system import reload_conf
|
2016-08-01 12:54:48 +03:00
|
|
|
|
2016-08-04 11:10:36 +03:00
|
|
|
|
2016-08-01 12:54:48 +03:00
|
|
|
# Load base configurations
|
2016-08-04 11:10:36 +03:00
|
|
|
surok_conf = '/etc/surok/conf/surok.json'
|
|
|
|
|
|
|
|
# Command line arguments
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('-c', '--config')
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.config:
|
|
|
|
surok_conf = args.config
|
|
|
|
|
|
|
|
f = open(surok_conf, 'r')
|
2016-08-01 12:54:48 +03:00
|
|
|
conf = json.loads(f.read())
|
|
|
|
print(conf)
|
2016-08-01 14:56:35 +03:00
|
|
|
f.close()
|
2016-08-01 12:54:48 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Get app configurations
|
|
|
|
def get_configs():
|
|
|
|
confs = [f for f in listdir(conf['confd']) if isfile(join(conf['confd'], f))]
|
|
|
|
return confs
|
|
|
|
|
|
|
|
|
2016-08-01 14:56:35 +03:00
|
|
|
# Get Surok App configuration
|
|
|
|
def load_app_conf(app):
|
|
|
|
f = open(conf['confd'] + '/' + app)
|
|
|
|
c = json.loads(f.read())
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
|
|
|
|
2016-08-01 12:54:48 +03:00
|
|
|
# Main loop
|
|
|
|
while 1:
|
|
|
|
confs = get_configs()
|
2016-08-01 14:56:35 +03:00
|
|
|
for app in confs:
|
|
|
|
app_conf = load_app_conf(app)
|
|
|
|
app_hosts = resolve(app_conf, conf)
|
2016-08-03 09:54:09 +03:00
|
|
|
my = { 'services': app_hosts }
|
2016-08-01 15:24:13 +03:00
|
|
|
service_conf = gen(my, app_conf['template'])
|
|
|
|
|
2016-08-01 16:09:07 +03:00
|
|
|
print(reload_conf(service_conf, app_conf))
|
2016-08-01 15:24:13 +03:00
|
|
|
|
2016-08-01 14:56:35 +03:00
|
|
|
|
2016-08-01 16:09:07 +03:00
|
|
|
sleep(conf['wait_time'])
|
2016-08-01 12:54:48 +03:00
|
|
|
|