mirror of
https://github.com/frappe/bench.git
synced 2024-11-11 15:51:03 +00:00
ammend and redo
This commit is contained in:
parent
2fdbdbfcf9
commit
bfc77c297d
44
bench/config/systemd.py
Normal file
44
bench/config/systemd.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import os, getpass, click
|
||||||
|
import 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('systemd/frappe-bench.target')
|
||||||
|
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', 'systemd/frappe-bench-redis-cache.service'),
|
||||||
|
"redis_socketio_config": os.path.join(bench_dir, 'config', 'systemd/frappe-bench-redis-socketio.service'),
|
||||||
|
"redis_queue_config": os.path.join(bench_dir, 'config', 'systemd/frappe-bench-redis-queue.service'),
|
||||||
|
"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)
|
@ -426,6 +426,35 @@ def restart_supervisor_processes(bench_path='.', web_workers=False):
|
|||||||
|
|
||||||
exec_cmd('sudo supervisorctl restart {group}'.format(group=group), cwd=bench_path)
|
exec_cmd('sudo supervisorctl restart {group}'.format(group=group), cwd=bench_path)
|
||||||
|
|
||||||
|
def restart_systemcd_processes(bench_path='.', web_workers=False):
|
||||||
|
from .config.common_site_config import get_config
|
||||||
|
conf = get_config(bench_path=bench_path)
|
||||||
|
bench_name = get_bench_name(bench_path)
|
||||||
|
|
||||||
|
cmd = conf.get('systemd_restart_cmd')
|
||||||
|
if cmd:
|
||||||
|
exec_cmd(cmd, cwd=bench_path)
|
||||||
|
|
||||||
|
else:
|
||||||
|
systemd_status = subprocess.check_output(['sudo', 'systemctl', 'status'], cwd=bench_path)
|
||||||
|
systemd_status = safe_decode(supervisor_status)
|
||||||
|
|
||||||
|
if web_workers and '{bench_name}-web:'.format(bench_name=bench_name) in systemd_status:
|
||||||
|
group = '{bench_name}-web: '.format(bench_name=bench_name)
|
||||||
|
|
||||||
|
elif '{bench_name}-workers:'.format(bench_name=bench_name) in systemd_status:
|
||||||
|
group = '{bench_name}-workers: {bench_name}-web:'.format(bench_name=bench_name)
|
||||||
|
|
||||||
|
# backward compatibility
|
||||||
|
elif '{bench_name}-processes:'.format(bench_name=bench_name) in systemd_status:
|
||||||
|
group = '{bench_name}-processes:'.format(bench_name=bench_name)
|
||||||
|
|
||||||
|
# backward compatibility
|
||||||
|
else:
|
||||||
|
group = 'frappe:'
|
||||||
|
|
||||||
|
exec_cmd('sudo systemctl restart {group}'.format(group=group), cwd=bench_path)
|
||||||
|
|
||||||
def set_default_site(site, bench_path='.'):
|
def set_default_site(site, bench_path='.'):
|
||||||
if not site in get_sites(bench_path=bench_path):
|
if not site in get_sites(bench_path=bench_path):
|
||||||
raise Exception("Site not in bench")
|
raise Exception("Site not in bench")
|
||||||
|
Loading…
Reference in New Issue
Block a user