Ejemplo n.º 1
0
def set_common_config(configs):
	import ast
	from zinuit.config.common_site_config import update_config

	common_site_config = {}
	for key, value in configs:
		if value in ("False", "True"):
			value = ast.literal_eval(value)

		elif "." in value:
			try:
				value = float(value)
			except ValueError:
				pass

		elif "{" in value or "[" in value:
			try:
				value = json.loads(value)
			except ValueError:
				pass

		else:
			try:
				value = int(value)
			except ValueError:
				pass

		common_site_config[key] = value

	update_config(common_site_config, zinuit_path='.')
Ejemplo n.º 2
0
def generate_supervisor_config(zinuit_path, user=None, yes=False):
    from zinuit.app import get_current_metel_version, use_rq
    from zinuit.utils import get_zinuit_name, find_executable
    from zinuit.config.common_site_config import get_config, update_config, get_gunicorn_workers

    template = zinuit.env.get_template('supervisor.conf')
    if not user:
        user = getpass.getuser()

    config = get_config(zinuit_path=zinuit_path)

    zinuit_dir = os.path.abspath(zinuit_path)

    config = template.render(
        **{
            "zinuit_dir":
            zinuit_dir,
            "sites_dir":
            os.path.join(zinuit_dir, 'sites'),
            "user":
            user,
            "metel_version":
            get_current_metel_version(zinuit_path),
            "use_rq":
            use_rq(zinuit_path),
            "http_timeout":
            config.get("http_timeout", 120),
            "redis_server":
            find_executable('redis-server'),
            "node":
            find_executable('node') or find_executable('nodejs'),
            "redis_cache_config":
            os.path.join(zinuit_dir, 'config', 'redis_cache.conf'),
            "redis_socketio_config":
            os.path.join(zinuit_dir, 'config', 'redis_socketio.conf'),
            "redis_queue_config":
            os.path.join(zinuit_dir, 'config', 'redis_queue.conf'),
            "webserver_port":
            config.get('webserver_port', 8000),
            "gunicorn_workers":
            config.get('gunicorn_workers',
                       get_gunicorn_workers()["gunicorn_workers"]),
            "zinuit_name":
            get_zinuit_name(zinuit_path),
            "background_workers":
            config.get('background_workers') or 1,
            "zinuit_cmd":
            find_executable('zinuit')
        })

    conf_path = os.path.join(zinuit_path, 'config', 'supervisor.conf')
    if not yes and os.path.exists(conf_path):
        click.confirm(
            'supervisor.conf already exists and this will overwrite it. Do you want to continue?',
            abort=True)

    with open(conf_path, 'w') as f:
        f.write(config)

    update_config({'restart_supervisor_on_update': True},
                  zinuit_path=zinuit_path)
    update_config({'restart_systemd_on_update': False},
                  zinuit_path=zinuit_path)
Ejemplo n.º 3
0
def generate_systemd_config(zinuit_path,
                            user=None,
                            yes=False,
                            stop=False,
                            create_symlinks=False,
                            delete_symlinks=False):

    if not user:
        user = getpass.getuser()

    config = get_config(zinuit_path=zinuit_path)

    zinuit_dir = os.path.abspath(zinuit_path)
    zinuit_name = get_zinuit_name(zinuit_path)

    if stop:
        exec_cmd(
            'sudo systemctl stop -- $(systemctl show -p Requires {zinuit_name}.target | cut -d= -f2)'
            .format(zinuit_name=zinuit_name))
        return

    if create_symlinks:
        _create_symlinks(zinuit_path)
        return

    if delete_symlinks:
        _delete_symlinks(zinuit_path)
        return

    number_of_workers = config.get('background_workers') or 1
    background_workers = []
    for i in range(number_of_workers):
        background_workers.append(
            get_zinuit_name(zinuit_path) + "-metel-default-worker@" +
            str(i + 1) + ".service")

    for i in range(number_of_workers):
        background_workers.append(
            get_zinuit_name(zinuit_path) + "-metel-short-worker@" +
            str(i + 1) + ".service")

    for i in range(number_of_workers):
        background_workers.append(
            get_zinuit_name(zinuit_path) + "-metel-long-worker@" + str(i + 1) +
            ".service")

    zinuit_info = {
        "zinuit_dir":
        zinuit_dir,
        "sites_dir":
        os.path.join(zinuit_dir, 'sites'),
        "user":
        user,
        "metel_version":
        get_current_metel_version(zinuit_path),
        "use_rq":
        use_rq(zinuit_path),
        "http_timeout":
        config.get("http_timeout", 120),
        "redis_server":
        find_executable('redis-server'),
        "node":
        find_executable('node') or find_executable('nodejs'),
        "redis_cache_config":
        os.path.join(zinuit_dir, 'config', 'redis_cache.conf'),
        "redis_socketio_config":
        os.path.join(zinuit_dir, 'config', 'redis_socketio.conf'),
        "redis_queue_config":
        os.path.join(zinuit_dir, 'config', 'redis_queue.conf'),
        "webserver_port":
        config.get('webserver_port', 8000),
        "gunicorn_workers":
        config.get('gunicorn_workers',
                   get_gunicorn_workers()["gunicorn_workers"]),
        "zinuit_name":
        get_zinuit_name(zinuit_path),
        "worker_target_wants":
        " ".join(background_workers),
        "zinuit_cmd":
        find_executable('zinuit')
    }

    if not yes:
        click.confirm(
            'current systemd configuration will be overwritten. Do you want to continue?',
            abort=True)

    setup_systemd_directory(zinuit_path)
    setup_main_config(zinuit_info, zinuit_path)
    setup_workers_config(zinuit_info, zinuit_path)
    setup_web_config(zinuit_info, zinuit_path)
    setup_redis_config(zinuit_info, zinuit_path)

    update_config({'restart_systemd_on_update': True}, zinuit_path=zinuit_path)
    update_config({'restart_supervisor_on_update': False},
                  zinuit_path=zinuit_path)
Ejemplo n.º 4
0
def config_http_timeout(seconds):
	"set http timeout"
	update_config({'http_timeout': seconds})
Ejemplo n.º 5
0
def config_serve_default_site(state):
	"Configure nginx to serve the default site on port 80"
	state = True if state == 'on' else False
	update_config({'serve_default_site': state})
Ejemplo n.º 6
0
def config_rebase_on_pull(state):
	"Rebase repositories on pulling"
	state = True if state == 'on' else False
	update_config({'rebase_on_pull': state})
Ejemplo n.º 7
0
def config_dns_multitenant(state):
	"Enable/Disable zinuit updates on running zinuit update"
	state = True if state == 'on' else False
	update_config({'dns_multitenant': state})
Ejemplo n.º 8
0
def config_update_zinuit_on_update(state):
	"Enable/Disable zinuit updates on running zinuit update"
	state = True if state == 'on' else False
	update_config({'update_zinuit_on_update': state})
Ejemplo n.º 9
0
def config_restart_systemd_on_update(state):
	"Enable/Disable auto restart of systemd units"
	state = True if state == 'on' else False
	update_config({'restart_systemd_on_update': state})
Ejemplo n.º 10
0
def config_restart_supervisor_on_update(state):
	"Enable/Disable auto restart of supervisor processes"
	state = True if state == 'on' else False
	update_config({'restart_supervisor_on_update': state})
Ejemplo n.º 11
0
def config_auto_update(state):
	"Enable/Disable auto update for zinuit"
	state = True if state == 'on' else False
	update_config({'auto_update': state})