2016-08-01 12:54:48 +03:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
from time import sleep
|
2016-08-09 15:40:07 +03:00
|
|
|
import os
|
2016-08-01 12:54:48 +03:00
|
|
|
from os import listdir
|
2016-08-09 14:13:20 +03:00
|
|
|
from os.path import isfile, join
|
2016-08-01 12:54:48 +03:00
|
|
|
import json
|
2017-01-11 00:24:14 +03:00
|
|
|
import argparse
|
2016-08-01 14:56:35 +03:00
|
|
|
from surok.templates import gen
|
2017-01-25 13:11:51 +03:00
|
|
|
from surok.discovery import Discovery
|
2016-08-01 15:24:13 +03:00
|
|
|
from surok.system import reload_conf
|
2017-01-25 13:11:51 +03:00
|
|
|
from surok.logger import Logger
|
2017-02-07 01:39:30 +03:00
|
|
|
from surok.config import Config
|
2016-08-01 12:54:48 +03:00
|
|
|
|
2017-02-07 01:58:13 +03:00
|
|
|
logger = Logger()
|
2016-08-04 11:10:36 +03:00
|
|
|
|
|
|
|
# Command line arguments
|
|
|
|
parser = argparse.ArgumentParser()
|
2016-11-06 22:24:26 +03:00
|
|
|
parser.add_argument('-c', '--config', help='surok.json path')
|
2016-08-04 11:10:36 +03:00
|
|
|
args = parser.parse_args()
|
2016-08-01 14:56:35 +03:00
|
|
|
|
2017-02-07 01:39:30 +03:00
|
|
|
# Load base configurations
|
2017-02-07 01:58:13 +03:00
|
|
|
config = Config(args.config if args.config else '/etc/surok/conf/surok.json')
|
2016-08-01 14:56:35 +03:00
|
|
|
|
2016-08-01 12:54:48 +03:00
|
|
|
# Main loop
|
2017-02-07 01:58:13 +03:00
|
|
|
#
|
2016-08-05 10:32:18 +03:00
|
|
|
|
2017-02-07 01:58:13 +03:00
|
|
|
discovery = Discovery()
|
2017-01-25 13:11:51 +03:00
|
|
|
|
2016-08-01 12:54:48 +03:00
|
|
|
while 1:
|
2017-01-25 13:11:51 +03:00
|
|
|
# Update config from discovery object
|
|
|
|
discovery.update_data()
|
2017-02-07 01:39:30 +03:00
|
|
|
for app in config.apps:
|
2017-01-25 13:11:51 +03:00
|
|
|
|
2017-02-07 01:39:30 +03:00
|
|
|
app_hosts = discovery.resolve(app)
|
2016-08-04 11:03:49 +03:00
|
|
|
|
2016-10-11 12:17:58 +03:00
|
|
|
# Populate my dictionary
|
|
|
|
my = {"services": app_hosts,
|
2017-02-07 01:39:30 +03:00
|
|
|
"conf_name": app['conf_name']}
|
2016-08-09 14:13:20 +03:00
|
|
|
|
2017-02-07 01:58:13 +03:00
|
|
|
logger.debug('my=', my)
|
2017-01-25 13:11:51 +03:00
|
|
|
|
2016-10-11 12:17:58 +03:00
|
|
|
# Generate config from template
|
2017-02-07 01:39:30 +03:00
|
|
|
service_conf = gen(my, app['template'])
|
2016-08-01 15:24:13 +03:00
|
|
|
|
2017-02-07 01:39:30 +03:00
|
|
|
reload_conf(service_conf, app, config, app_hosts)
|
2016-08-01 15:24:13 +03:00
|
|
|
|
2017-02-07 01:39:30 +03:00
|
|
|
sleep(config['wait_time'])
|