def index(): if 'auth_token' in session: ctx = {} try: applications = utils.get_node_applications() apps = [] for app in applications: json_data = json.loads(utils.get_application_config(app)) app_data = { 'name': app, 'version': json_data['version'], 'instances': json_data['instances'][settings.NODE_NAME], 'runtime': json_data['runtime'], } apps.append(app_data) ctx = { 'applications': apps, } except Exception, e: import traceback traceback.print_exc() flash(e, 'error') return render_template("index.html", **ctx)
def remove_application(app_name=None): """ Removes and application :keyword app_name: Name of application to remove """ if not app_name: raise NameError("You must specify an application name") log = config.get_logger("remove_application") errors = {} output = {} if app_name not in utils.get_node_applications(): raise NameError("Application not deployed to this node") app_config = utils.get_application_config(app_name) try: app_config = json.loads(app_config) # attempt to stop application first stop_application(app_name) except: pass # ignore errors on removal # remove configs app_state_dir = os.path.join(settings.APPLICATION_STATE_DIR, app_name) app_dir = os.path.join(settings.APPLICATION_BASE_DIR, app_name) ve_dir = os.path.join(settings.VIRTUALENV_BASE_DIR, app_name) if os.path.exists(app_state_dir): shutil.rmtree(app_state_dir) output["app_state_dir"] = "removed" if os.path.exists(app_dir): shutil.rmtree(app_dir) output["app_dir"] = "removed" if os.path.exists(ve_dir): shutil.rmtree(ve_dir) output["ve_dir"] = "removed" # clear nginx configs for conf in os.listdir(settings.WEBSERVER_CONF_DIR): if re.search("{0}*".format(app_name), conf): os.remove(os.path.join(settings.WEBSERVER_CONF_DIR, conf)) output["nginx_configs"] = "removed" # clear uwsgi configs for conf in os.listdir(settings.SUPERVISOR_CONF_DIR): if re.search("uwsgi_{0}*".format(app_name), conf): os.remove(os.path.join(settings.SUPERVISOR_CONF_DIR, conf)) output["uwsgi_configs"] = "removed" # clear logs for log_file in os.listdir(settings.APPLICATION_LOG_DIR): if re.search("{0}*".format(app_name), log_file): os.remove(os.path.join(settings.APPLICATION_LOG_DIR, log_file)) # get app config to remove reserved instances if app_config: for instance in app_config["instances"][settings.NODE_NAME]: log.debug("{0}: releasing port: {1}".format(app_name, instance)) utils.release_application_port(instance) output["reserved_ports"] = "released" # remove app config utils.remove_application_config(app_name) # remove from node app list utils.remove_app_from_node_app_list(app_name) # signal supervisor to update p = Popen(["supervisorctl", "update"], stdout=PIPE, stderr=PIPE) p_out, p_err = p.stdout.read().strip(), p.stderr.read().strip() output["supervisorctl_out"] = p_out output["supervisorctl_err"] = p_err log.info("{0}: application removed".format(app_name)) data = {"status": "complete", "output": output, "errors": errors, "operation": "remove_application"} return data