This commit is contained in:
Difrex 2016-08-04 11:06:33 +03:00
commit 082b11a47d
9 changed files with 47 additions and 10 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
surok/__pycache__
__pycache__
*.pyc
*.swp

View File

@ -1 +0,0 @@
{}

12
conf.d/selfcheck.json Normal file
View File

@ -0,0 +1,12 @@
{
"services": [
{
"name": "",
"group": "mesos"
}
],
"conf_name": "selfcheck",
"template": "templates/selfcheck.jj2",
"dest": "selfcheck",
"reload_cmd": "/bin/echo selfcheck ok"
}

View File

@ -1,4 +1,7 @@
{
"marathon": "10.0.1.199:8080",
"confd": "conf.d"
"marathon": "TODO",
"confd": "conf.d",
"domain": "marathon.mesos",
"wait_time": 20,
"lock_dir": "/var/tmp"
}

View File

@ -1,11 +1,18 @@
import dns.resolver
def resolve(app, conf):
hosts = []
hosts = {}
services = app['services']
domain = conf['domain']
for rdata in dns.resolver.query('_' + app['name'] + '.' + app['group'] + '._tcp.' + domain, 'SRV'):
info = str(rdata).split()
server = { 'name': info[3], 'port': info[2] }
hosts.append(server)
for service in services:
hosts[service['name']] = []
try:
for rdata in dns.resolver.query('_' + service['name'] + '.' + service['group'] + '._tcp.' + domain, 'SRV'):
info = str(rdata).split()
server = { 'name': info[3], 'port': info[2] }
hosts[ service['name'] ].append(server)
except Exception as e:
print("Could not resolve " + service['name'] + '.' + service['group'] + '._tcp.' + domain)
return hosts

View File

@ -28,14 +28,14 @@ def write_lock(name, service_conf):
def reload_conf(service_conf, app_conf):
# Check old config
if get_old(app_conf['name'], service_conf) != 1:
if get_old(app_conf['conf_name'], service_conf) != 1:
print('Write new configuration')
f = open(app_conf['dest'], 'w')
f.write(service_conf)
f.close()
write_lock(app_conf['name'], service_conf)
write_lock(app_conf['conf_name'], service_conf)
# Reload conf
stdout = os.popen(app_conf['reload_cmd']).read()

View File

@ -1,4 +1,5 @@
from jinja2 import Environment, PackageLoader, Template
import os
# Return rendered configuration
@ -8,5 +9,6 @@ def gen(my, jj2):
f.close()
template = Template(temp)
my['env'] = os.environ
return template.render(my=my)

11
templates/nginx_proxy.jj2 Normal file
View File

@ -0,0 +1,11 @@
{% for host in my['hosts'] %}
server {{host['kioskservice']['name']}}:{{host['kioskservice']['port']}};
{% endfor %}
server {
listen 0.0.0.0:80;
server_name _;
location / {
}
}

1
templates/selfcheck.jj2 Normal file
View File

@ -0,0 +1 @@
OK