コード例 #1
0
def generate_supervisor_config(bench_path, user=None, force=False):
    from bench.app import get_current_frappe_version, use_rq
    from bench.utils import get_bench_name, find_executable
    from bench.config.common_site_config import get_config, update_config, get_gunicorn_workers

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

    config = get_config(bench=bench_path)

    bench_dir = os.path.abspath(bench_path)

    config = template.render(
        **{
            "bench_dir":
            bench_dir,
            "sites_dir":
            os.path.join(bench_dir, 'sites'),
            "user":
            user,
            "frappe_version":
            get_current_frappe_version(bench_path),
            "use_rq":
            use_rq(bench_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(bench_dir, 'config', 'redis_cache.conf'),
            "redis_socketio_config":
            os.path.join(bench_dir, 'config', 'redis_socketio.conf'),
            "redis_queue_config":
            os.path.join(bench_dir, 'config', 'redis_queue.conf'),
            "webserver_port":
            config.get('webserver_port', 8000),
            "gunicorn_workers":
            config.get('gunicorn_workers',
                       get_gunicorn_workers()["gunicorn_workers"]),
            "bench_name":
            get_bench_name(bench_path),
            "background_workers":
            config.get('background_workers') or 1
        })

    conf_path = os.path.join(bench_path, 'config', 'supervisor.conf')
    if not force 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}, bench=bench_path)
コード例 #2
0
ファイル: procfile.py プロジェクト: lodhabhagya/bench-repo
def setup_procfile(bench_path, yes=False):
	config = get_config(bench_path=bench_path)
	procfile_path = os.path.join(bench_path, 'Procfile')
	if not yes and os.path.exists(procfile_path):
		click.confirm('A Procfile already exists and this will overwrite it. Do you want to continue?',
			abort=True)

	procfile = bench.env.get_template('Procfile').render(
		node=find_executable("node") or find_executable("nodejs"),
		use_rq=use_rq(bench_path),
		webserver_port=config.get('webserver_port'))

	with open(procfile_path, 'w') as f:
		f.write(procfile)
コード例 #3
0
ファイル: supervisor.py プロジェクト: Nayar/bench
def generate_supervisor_config(bench_path, user=None, yes=False):
	from bench.app import get_current_frappe_version, use_rq
	from bench.utils import get_bench_name, find_executable
	from bench.config.common_site_config import get_config, update_config, get_gunicorn_workers

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

	config = get_config(bench_path=bench_path)

	bench_dir = os.path.abspath(bench_path)

	config = template.render(**{
		"bench_dir": bench_dir,
		"sites_dir": os.path.join(bench_dir, 'sites'),
		"user": user,
		"frappe_version": get_current_frappe_version(bench_path),
		"use_rq": use_rq(bench_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(bench_dir, 'config', 'redis_cache.conf'),
		"redis_socketio_config": os.path.join(bench_dir, 'config', 'redis_socketio.conf'),
		"redis_queue_config": os.path.join(bench_dir, 'config', 'redis_queue.conf'),
		"webserver_port": config.get('webserver_port', 8000),
		"gunicorn_workers": config.get('gunicorn_workers', get_gunicorn_workers()["gunicorn_workers"]),
		"bench_name": get_bench_name(bench_path),
		"background_workers": config.get('background_workers') or 1,
		"bench_cmd": find_executable('bench')
	})

	conf_path = os.path.join(bench_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}, bench_path=bench_path)
	update_config({'restart_systemd_on_update': False}, bench_path=bench_path)
コード例 #4
0
ファイル: systemd.py プロジェクト: dataent/bench
def generate_systemd_config(bench_path,
                            user=None,
                            yes=False,
                            stop=False,
                            create_symlinks=False,
                            delete_symlinks=False):

    if not user:
        user = getpass.getuser()

    config = get_config(bench_path=bench_path)

    bench_dir = os.path.abspath(bench_path)
    bench_name = get_bench_name(bench_path)

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

    if create_symlinks:
        _create_symlinks(bench_path)
        return

    if delete_symlinks:
        _delete_symlinks(bench_path)
        return

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

    for i in range(number_of_workers):
        background_workers.append(
            get_bench_name(bench_path) + "-dataent-short-worker@" +
            str(i + 1) + ".service")

    for i in range(number_of_workers):
        background_workers.append(
            get_bench_name(bench_path) + "-dataent-long-worker@" + str(i + 1) +
            ".service")

    bench_info = {
        "bench_dir":
        bench_dir,
        "sites_dir":
        os.path.join(bench_dir, 'sites'),
        "user":
        user,
        "dataent_version":
        get_current_dataent_version(bench_path),
        "use_rq":
        use_rq(bench_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(bench_dir, 'config', 'redis_cache.conf'),
        "redis_socketio_config":
        os.path.join(bench_dir, 'config', 'redis_socketio.conf'),
        "redis_queue_config":
        os.path.join(bench_dir, 'config', 'redis_queue.conf'),
        "webserver_port":
        config.get('webserver_port', 8000),
        "gunicorn_workers":
        config.get('gunicorn_workers',
                   get_gunicorn_workers()["gunicorn_workers"]),
        "bench_name":
        get_bench_name(bench_path),
        "worker_target_wants":
        " ".join(background_workers),
        "bench_cmd":
        find_executable('bench')
    }

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

    setup_systemd_directory(bench_path)
    setup_main_config(bench_info, bench_path)
    setup_workers_config(bench_info, bench_path)
    setup_web_config(bench_info, bench_path)
    setup_redis_config(bench_info, bench_path)

    update_config({'restart_systemd_on_update': True}, bench_path=bench_path)
    update_config({'restart_supervisor_on_update': False},
                  bench_path=bench_path)
コード例 #5
0
ファイル: systemd.py プロジェクト: Nayar/bench
def generate_systemd_config(bench_path, user=None, yes=False,
	stop=False, create_symlinks=False,
	delete_symlinks=False):

	if not user:
		user = getpass.getuser()

	config = get_config(bench_path=bench_path)

	bench_dir = os.path.abspath(bench_path)
	bench_name = get_bench_name(bench_path)

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

	if create_symlinks:
		_create_symlinks(bench_path)
		return

	if delete_symlinks:
		_delete_symlinks(bench_path)
		return

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

	for i in range(number_of_workers):
		background_workers.append(get_bench_name(bench_path) + "-frappe-short-worker@" + str(i+1) + ".service")

	for i in range(number_of_workers):
		background_workers.append(get_bench_name(bench_path) + "-frappe-long-worker@" + str(i+1) + ".service")

	bench_info = {
		"bench_dir": bench_dir,
		"sites_dir": os.path.join(bench_dir, 'sites'),
		"user": user,
		"frappe_version": get_current_frappe_version(bench_path),
		"use_rq": use_rq(bench_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(bench_dir, 'config', 'redis_cache.conf'),
		"redis_socketio_config": os.path.join(bench_dir, 'config', 'redis_socketio.conf'),
		"redis_queue_config": os.path.join(bench_dir, 'config', 'redis_queue.conf'),
		"webserver_port": config.get('webserver_port', 8000),
		"gunicorn_workers": config.get('gunicorn_workers', get_gunicorn_workers()["gunicorn_workers"]),
		"bench_name": get_bench_name(bench_path),
		"worker_target_wants": " ".join(background_workers),
		"bench_cmd": find_executable('bench')
	}

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

	setup_systemd_directory(bench_path)
	setup_main_config(bench_info, bench_path)
	setup_workers_config(bench_info, bench_path)
	setup_web_config(bench_info, bench_path)
	setup_redis_config(bench_info, bench_path)

	update_config({'restart_systemd_on_update': True}, bench_path=bench_path)
	update_config({'restart_supervisor_on_update': False}, bench_path=bench_path)