Marathon restart implementation

This commit is contained in:
Difrex 2016-10-14 11:25:53 +03:00
parent 73cf76cd86
commit d15a23774c
3 changed files with 28 additions and 1 deletions

View File

@ -1,7 +1,8 @@
{ {
"marathon": { "marathon": {
"force": true, "force": true,
"host": "marathon.mesos:8080" "host": "http://marathon.mesos:8080",
"enabled": true
}, },
"confd": "/etc/surok/conf.d", "confd": "/etc/surok/conf.d",
"domain": "marathon.mesos", "domain": "marathon.mesos",

View File

@ -92,6 +92,7 @@ def get_group(service, app):
# Parse MARATHON_APP_ID # Parse MARATHON_APP_ID
# Return marathon.group
def parse_marathon_app_id(marathon_app_id): def parse_marathon_app_id(marathon_app_id):
marathon_app_id = marathon_app_id.split('/') marathon_app_id = marathon_app_id.split('/')
group = '' group = ''

View File

@ -1,5 +1,6 @@
import os import os
import logging import logging
import requests
# Get old configuration # Get old configuration
@ -50,6 +51,10 @@ def reload_conf(service_conf, app_conf, first, conf):
logging.info(stdout) logging.info(stdout)
return first return first
# Check marathon enabled in configuration
if conf['marathon']['enabled'] is True:
restart_self_in_marathon(conf['marathon'])
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)
@ -60,3 +65,23 @@ def reload_conf(service_conf, app_conf, first, conf):
app_conf['conf_name'] + app_conf['conf_name'] +
' Skip reload') ' Skip reload')
return first return first
# Do POST request to marathon API
# /v2/apps//app/name/restart
def restart_self_in_marathon(marathon):
host = marathon['host']
# Check MARATHON_APP_ID environment varible
if os.environ.get('MARATHON_APP_ID') is not True:
logging.error('Cannot find MARATHON_APP_ID. Not in Mesos?')
sys.exit(2)
app_id = os.environ['MARATHON_APP_ID']
uri = 'http://' + host + '/v2/apps/' + app_id + '/restart'
# Ok. In this step we made restart request to Marathon
if marathon['force'] is True:
r = requests.post(uri, data = {'force': 'true'})
else:
r = requests.post(uri, data = {})