Memcached support. Initial.

This commit is contained in:
Difrex 2016-11-06 22:24:26 +03:00
parent 6650c7bc85
commit 39fad5700f
3 changed files with 45 additions and 16 deletions

View File

@ -2,11 +2,21 @@
"marathon": { "marathon": {
"force": true, "force": true,
"host": "http://marathon.mesos:8080", "host": "http://marathon.mesos:8080",
"enabled": true "enabled": false
}, },
"confd": "/etc/surok/conf.d", "confd": "/etc/surok/conf.d",
"domain": "marathon.mesos", "domain": "marathon.mesos",
"wait_time": 20, "wait_time": 20,
"lock_dir": "/var/tmp", "lock_dir": "/var/tmp",
"loglevel": "info" "loglevel": "info",
"container": false,
"memcached": {
"enabled": false,
"discovery": {
"enabled": false,
"service": "memcached",
"group": "system"
},
"hosts": ["localhost:11211"]
}
} }

View File

@ -16,7 +16,7 @@ surok_conf = '/etc/surok/conf/surok.json'
# Command line arguments # Command line arguments
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config') parser.add_argument('-c', '--config', help='surok.json path')
args = parser.parse_args() args = parser.parse_args()
if args.config: if args.config:
surok_conf = args.config surok_conf = args.config
@ -51,10 +51,6 @@ def load_app_conf(app):
# Main loop # Main loop
########### ###########
# Bad hack for detect first run
# On host system set it to False
# TODO: put it to config
first = True
while 1: while 1:
confs = get_configs() confs = get_configs()
for app in confs: for app in confs:
@ -77,6 +73,6 @@ while 1:
# Generate config from template # Generate config from template
service_conf = gen(my, app_conf['template']) service_conf = gen(my, app_conf['template'])
first = reload_conf(service_conf, app_conf, first, conf) reload_conf(service_conf, app_conf, conf, app_hosts)
sleep(conf['wait_time']) sleep(conf['wait_time'])

View File

@ -2,6 +2,7 @@ import os
import sys import sys
import logging import logging
import requests import requests
import memcache
# Get old configuration # Get old configuration
@ -22,6 +23,12 @@ def get_old(name, service_conf):
return 0 return 0
# Get old discovered servers from memcache
def get_old_from_memcache(mc, name, service_conf):
mc_servers_key = 'surok_' + name + '_servers'
old_servers = mc.get(mc_servers_key)
def write_lock(name, service_conf): def write_lock(name, service_conf):
path = '/var/tmp/surok.' + name path = '/var/tmp/surok.' + name
f = open(path, 'w') f = open(path, 'w')
@ -43,29 +50,45 @@ def do_reload(service_conf, app_conf):
return stdout return stdout
def reload_conf(service_conf, app_conf, first, conf): def reload_conf(service_conf, app_conf, conf, app_hosts):
# Check first loop # Check first loop
if first is True: #if first is True:
stdout = do_reload(service_conf, app_conf) # stdout = do_reload(service_conf, app_conf)
first = False # first = False
logging.info(stdout) # logging.info(stdout)
return first # return first
# Check marathon enabled in configuration # Check marathon enabled in configuration
if conf['marathon']['enabled'] is True: if conf['marathon']['enabled'] is True:
restart_self_in_marathon(conf['marathon']) restart_self_in_marathon(conf['marathon'])
# Check memcache
# Need rewriting
################
if 'memcached' in conf:
if conf['memcached']['enabled'] is True:
# Check old servers
if conf['memcached']['discovery']['enabled'] is True:
logging.info('Discovery of Memcached not implemented')
mc = memcache.Client(conf['memcached']['hosts'])
get_old_from_memcache(mc, name, service_conf)
else:
logging.warning('DEPRECATED main conf file. Please use new syntax!')
# End of memcache block
#######################
if get_old(app_conf['conf_name'], service_conf) != 1: if get_old(app_conf['conf_name'], service_conf) != 1:
stdout = do_reload(service_conf, app_conf) stdout = do_reload(service_conf, app_conf)
logging.info(stdout) logging.info(stdout)
return first return
else: else:
if conf['loglevel'] == 'debug': if conf['loglevel'] == 'debug':
logging.debug('Same config ' + logging.debug('Same config ' +
app_conf['conf_name'] + app_conf['conf_name'] +
' Skip reload') ' Skip reload')
return first return
# Do POST request to marathon API # Do POST request to marathon API