def POST(self): try: # 'startsecs=0' is to avoid restarting consul after `consul leave`. os.system( 'sed -i \'/autorestart=true/cautorestart=false\' /etc/supervisor/conf.d/consul.conf' ) os.system('echo startsecs=0 >> /etc/supervisor/conf.d/consul.conf') os.system('supervisorctl update consul') # As 'supervisorctl update' will restart Consul, we have to wait for it to be running. deadline = time.time() + 15 while time.time() < deadline: try: get_current_datacenter() break except: time.sleep(1) deregister_services(gethostname()) os.system('consul leave') finally: post_data = json.loads(web.data() or '{}') runtime_settings_path = '/opt/armada/runtime_settings.json' if not post_data.get('keep-joined') and os.path.isfile( runtime_settings_path): with open(runtime_settings_path) as f: runtime_settings = json.load(f) runtime_settings['ships'] = [] runtime_settings['is_commander'] = True with open(runtime_settings_path, 'w') as f: json.dump(runtime_settings, f, sort_keys=True, indent=4) return self.status_ok({'message': 'Shutdown complete.'})
def POST(self): # 'startsecs=0' is to avoid restarting consul after `consul leave`. os.system('sed -i \'/autorestart=true/cautorestart=false\' /etc/supervisor/conf.d/consul.conf') os.system('echo startsecs=0 >> /etc/supervisor/conf.d/consul.conf') os.system('supervisorctl update consul') # As 'supervisorctl update' will restart Consul, we have to wait for it to be running. while True: try: get_current_datacenter() break except: pass deregister_services(gethostname()) os.system('consul leave') return self.status_ok({'message': 'Shutdown complete.'})
def _save_runtime_settings(): consul_settings = {} consul_settings['is_commander'] = is_ship_commander() consul_settings['name'] = get_ship_name() consul_settings['ships'] = get_other_ship_ips() consul_settings['datacenter'] = get_current_datacenter() consul_settings['dockyards'] = alias.get_list() with open(consul_config.RUNTIME_SETTINGS_PATH, 'w') as runtime_settings: runtime_settings.write(json.dumps(consul_settings, sort_keys=True, indent=4))
def _save_runtime_settings(): consul_settings = {} consul_settings['is_commander'] = is_ship_commander() consul_settings['name'] = get_ship_name() consul_settings['ships'] = get_other_ship_ips() consul_settings['datacenter'] = get_current_datacenter() consul_settings['dockyards'] = alias.get_list() with open(consul_config.RUNTIME_SETTINGS_PATH, 'w') as runtime_settings: runtime_settings.write( json.dumps(consul_settings, sort_keys=True, indent=4))
def POST(self): # 'startsecs=0' is to avoid restarting consul after `consul leave`. os.system( 'sed -i \'/autorestart=true/cautorestart=false\' /etc/supervisor/conf.d/consul.conf' ) os.system('echo startsecs=0 >> /etc/supervisor/conf.d/consul.conf') os.system('supervisorctl update consul') # As 'supervisorctl update' will restart Consul, we have to wait for it to be running. while True: try: get_current_datacenter() break except: pass deregister_services(gethostname()) os.system('consul leave') return self.status_ok({'message': 'Shutdown complete.'})
def on_post(self, req, resp): try: # 'startsecs=0' is to avoid restarting consul after `consul leave`. check_call( 'sed -i \'/autorestart=true/cautorestart=false\' /etc/supervisor/conf.d/consul.conf', shell=True) check_call( 'echo startsecs=0 >> /etc/supervisor/conf.d/consul.conf', shell=True) check_call(['supervisorctl', 'update', 'consul']) # As 'supervisorctl update' will restart Consul, we have to wait for it to be running. deadline = time.time() + 15 ok = False while time.time() < deadline: try: get_current_datacenter() ok = True break except Exception: time.sleep(1) if not ok: get_logger().warn('Restarting consul timed out.') deregister_services(gethostname()) check_call(['consul', 'leave']) finally: post_data = req.json runtime_settings_path = '/opt/armada/runtime_settings.json' if not post_data.get('keep-joined') and os.path.isfile( runtime_settings_path): with open(runtime_settings_path) as f: runtime_settings = json.load(f) runtime_settings['ships'] = [] runtime_settings['is_commander'] = True with open(runtime_settings_path, 'w') as f: json.dump(runtime_settings, f, sort_keys=True, indent=4) return self.status_ok(resp, {'message': 'Shutdown complete.'})