コード例 #1
0
ファイル: supervisor.py プロジェクト: Bradeskojest/bench
def generate_supervisor_config(bench_path, user=None):
	from bench.app import get_current_frappe_version
	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,
		"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'),
		"frappe_version": get_current_frappe_version(),
		"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)
	})

	with open(os.path.join(bench_path, 'config', 'supervisor.conf'), 'w') as f:
		f.write(config)

	update_config({'restart_supervisor_on_update': True}, bench=bench_path)
コード例 #2
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)
コード例 #3
0
def bench_command(bench='.'):
    "Bench manager for Frappe"
    from bench.app import get_current_frappe_version
    from bench.utils import setup_logging

    # TODO add bench path context
    global FRAPPE_VERSION
    FRAPPE_VERSION = get_current_frappe_version()
    setup_logging(bench=bench)
コード例 #4
0
ファイル: __init__.py プロジェクト: Bradeskojest/bench
def bench_command(bench='.'):
	"Bench manager for Frappe"
	from bench.app import get_current_frappe_version
	from bench.utils import setup_logging

	# TODO add bench path context
	global FRAPPE_VERSION
	FRAPPE_VERSION = get_current_frappe_version()
	setup_logging(bench=bench)
コード例 #5
0
def generate_supervisor_config(bench_path, user=None):
    from bench.app import get_current_frappe_version
    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,
            "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'),
            "frappe_version":
            get_current_frappe_version(),
            "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)
        })

    with open(os.path.join(bench_path, 'config', 'supervisor.conf'), 'w') as f:
        f.write(config)

    update_config({'restart_supervisor_on_update': True}, bench=bench_path)
コード例 #6
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)
コード例 #7
0
def execute(bench_path):
	frappe_branch = get_current_branch('frappe', bench_path)
	frappe_version = get_current_frappe_version(bench_path)

	if not (frappe_branch=='develop' or frappe_version >= 7):
		# not version 7+
		# prevent running this patch
		return False

	click.confirm('\nThis update will remove Celery config and prepare the bench to use Python RQ.\n'
		'And it will overwrite Procfile and supervisor.conf.\n'
		'If you don\'t know what this means, type Y ;)\n\n'
		'Do you want to continue?',
		abort=True)

	setup_procfile(bench_path, yes=True)

	# if production setup
	if os.path.exists(os.path.join(bench_path, 'config', 'supervisor.conf')):
		generate_supervisor_config(bench_path, yes=True)
コード例 #8
0
ファイル: systemd.py プロジェクト: gaisano-erp/Gaisano-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)
コード例 #9
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)