Memcached support. Initial.
This commit is contained in:
parent
6650c7bc85
commit
39fad5700f
@ -2,11 +2,21 @@
|
||||
"marathon": {
|
||||
"force": true,
|
||||
"host": "http://marathon.mesos:8080",
|
||||
"enabled": true
|
||||
"enabled": false
|
||||
},
|
||||
"confd": "/etc/surok/conf.d",
|
||||
"domain": "marathon.mesos",
|
||||
"wait_time": 20,
|
||||
"lock_dir": "/var/tmp",
|
||||
"loglevel": "info"
|
||||
"loglevel": "info",
|
||||
"container": false,
|
||||
"memcached": {
|
||||
"enabled": false,
|
||||
"discovery": {
|
||||
"enabled": false,
|
||||
"service": "memcached",
|
||||
"group": "system"
|
||||
},
|
||||
"hosts": ["localhost:11211"]
|
||||
}
|
||||
}
|
||||
|
8
surok.py
8
surok.py
@ -16,7 +16,7 @@ surok_conf = '/etc/surok/conf/surok.json'
|
||||
|
||||
# Command line arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-c', '--config')
|
||||
parser.add_argument('-c', '--config', help='surok.json path')
|
||||
args = parser.parse_args()
|
||||
if args.config:
|
||||
surok_conf = args.config
|
||||
@ -51,10 +51,6 @@ def load_app_conf(app):
|
||||
# Main loop
|
||||
###########
|
||||
|
||||
# Bad hack for detect first run
|
||||
# On host system set it to False
|
||||
# TODO: put it to config
|
||||
first = True
|
||||
while 1:
|
||||
confs = get_configs()
|
||||
for app in confs:
|
||||
@ -77,6 +73,6 @@ while 1:
|
||||
# Generate config from 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'])
|
||||
|
@ -2,6 +2,7 @@ import os
|
||||
import sys
|
||||
import logging
|
||||
import requests
|
||||
import memcache
|
||||
|
||||
|
||||
# Get old configuration
|
||||
@ -22,6 +23,12 @@ def get_old(name, service_conf):
|
||||
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):
|
||||
path = '/var/tmp/surok.' + name
|
||||
f = open(path, 'w')
|
||||
@ -43,29 +50,45 @@ def do_reload(service_conf, app_conf):
|
||||
return stdout
|
||||
|
||||
|
||||
def reload_conf(service_conf, app_conf, first, conf):
|
||||
def reload_conf(service_conf, app_conf, conf, app_hosts):
|
||||
|
||||
# Check first loop
|
||||
if first is True:
|
||||
stdout = do_reload(service_conf, app_conf)
|
||||
first = False
|
||||
logging.info(stdout)
|
||||
return first
|
||||
#if first is True:
|
||||
# stdout = do_reload(service_conf, app_conf)
|
||||
# first = False
|
||||
# logging.info(stdout)
|
||||
# return first
|
||||
|
||||
# Check marathon enabled in configuration
|
||||
if conf['marathon']['enabled'] is True:
|
||||
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:
|
||||
stdout = do_reload(service_conf, app_conf)
|
||||
logging.info(stdout)
|
||||
return first
|
||||
return
|
||||
else:
|
||||
if conf['loglevel'] == 'debug':
|
||||
logging.debug('Same config ' +
|
||||
app_conf['conf_name'] +
|
||||
' Skip reload')
|
||||
return first
|
||||
return
|
||||
|
||||
|
||||
# Do POST request to marathon API
|
||||
|
Loading…
Reference in New Issue
Block a user