surok/surok.py

49 lines
1.1 KiB
Python
Raw Permalink Normal View History

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
from surok.discovery import Discovery
2016-08-01 15:24:13 +03:00
from surok.system import reload_conf
from surok.logger import Logger
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
# 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()
2016-08-01 12:54:48 +03:00
while 1:
# Update config from discovery object
discovery.update_data()
for app in config.apps:
app_hosts = discovery.resolve(app)
2016-10-11 12:17:58 +03:00
# Populate my dictionary
my = {"services": app_hosts,
"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)
2016-10-11 12:17:58 +03:00
# Generate config from template
service_conf = gen(my, app['template'])
2016-08-01 15:24:13 +03:00
reload_conf(service_conf, app, config, app_hosts)
2016-08-01 15:24:13 +03:00
sleep(config['wait_time'])