mirror of
https://github.com/frappe/bench.git
synced 2025-01-08 16:14:12 +00:00
[fix] 6–7 compatibility
This commit is contained in:
parent
618ae53c91
commit
6155e6aaa0
@ -1,14 +1,20 @@
|
||||
import bench, os, click
|
||||
from bench.utils import find_executable
|
||||
from bench.app import get_current_frappe_version, get_current_branch
|
||||
from bench.config.common_site_config import get_config
|
||||
|
||||
def setup_procfile(bench_path, force=False):
|
||||
config = get_config(bench=bench_path)
|
||||
procfile_path = os.path.join(bench_path, 'Procfile')
|
||||
if not force 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"))
|
||||
procfile = bench.env.get_template('Procfile').render(
|
||||
node=find_executable("node") or find_executable("nodejs"),
|
||||
frappe_version=get_current_frappe_version(),
|
||||
frappe_branch=get_current_branch('frappe', bench_path),
|
||||
webserver_port=config.get('webserver_port'))
|
||||
|
||||
with open(procfile_path, 'w') as f:
|
||||
f.write(procfile)
|
||||
|
@ -2,7 +2,7 @@ import os, getpass, click
|
||||
import bench
|
||||
|
||||
def generate_supervisor_config(bench_path, user=None, force=False):
|
||||
from bench.app import get_current_frappe_version
|
||||
from bench.app import get_current_frappe_version, get_current_branch
|
||||
from bench.utils import get_bench_name, find_executable
|
||||
from bench.config.common_site_config import get_config, update_config, get_gunicorn_workers
|
||||
|
||||
@ -18,13 +18,14 @@ def generate_supervisor_config(bench_path, user=None, force=False):
|
||||
"bench_dir": bench_dir,
|
||||
"sites_dir": os.path.join(bench_dir, 'sites'),
|
||||
"user": user,
|
||||
"frappe_version": get_current_frappe_version(),
|
||||
"frappe_branch": get_current_branch('frappe', 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'),
|
||||
"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),
|
||||
|
@ -1,10 +1,19 @@
|
||||
{%- set use_rq = (frappe_branch=='develop' or frappe_version >= 7) -%}
|
||||
redis_cache: redis-server config/redis_cache.conf
|
||||
redis_socketio: redis-server config/redis_socketio.conf
|
||||
redis_queue: redis-server config/redis_queue.conf
|
||||
web: bench serve
|
||||
web: bench serve {% if webserver_port -%} --port {{ webserver_port }} {%- endif %}
|
||||
|
||||
socketio: {{ node }} apps/frappe/socketio.js
|
||||
watch: bench watch
|
||||
{% if use_rq -%}
|
||||
schedule: bench schedule
|
||||
worker_short: bench worker --queue short
|
||||
worker_long: bench worker --queue long
|
||||
worker_default: bench worker --queue default
|
||||
{% else %}
|
||||
workerbeat: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app beat -s scheduler.schedule'
|
||||
worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker -n jobs@%h -Ofair --soft-time-limit 360 --time-limit 390'
|
||||
longjob_worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker -n longjobs@%h -Ofair --soft-time-limit 1500 --time-limit 1530'
|
||||
async_worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker -n async@%h -Ofair --soft-time-limit 1500 --time-limit 1530'
|
||||
{%- endif %}
|
||||
|
@ -1,3 +1,4 @@
|
||||
{%- set use_rq = (frappe_branch=='develop' or frappe_version >= 7) -%}
|
||||
; Notes:
|
||||
; priority=1 --> Lower priorities indicate programs that start first and shut down last
|
||||
; killasgroup=true --> send kill signal to child processes too
|
||||
@ -12,6 +13,7 @@ stderr_logfile={{ bench_dir }}/logs/web.error.log
|
||||
user={{ user }}
|
||||
directory={{ sites_dir }}
|
||||
|
||||
{% if use_rq %}
|
||||
[program:{{ bench_name }}-frappe-schedule]
|
||||
command=bench schedule
|
||||
priority=3
|
||||
@ -64,6 +66,55 @@ killasgroup=true
|
||||
numprocs={{ background_workers }}
|
||||
process_name=%(program_name)s-%(process_num)d
|
||||
|
||||
{% else %}
|
||||
[program:{{ bench_name }}-frappe-workerbeat]
|
||||
command={{ bench_dir }}/env/bin/python -m frappe.celery_app beat -s beat.schedule
|
||||
priority=3
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stdout_logfile={{ bench_dir }}/logs/workerbeat.log
|
||||
stderr_logfile={{ bench_dir }}/logs/workerbeat.error.log
|
||||
user={{ user }}
|
||||
directory={{ sites_dir }}
|
||||
|
||||
[program:{{ bench_name }}-frappe-worker]
|
||||
command={{ bench_dir }}/env/bin/python -m frappe.celery_app worker -n jobs@%%h -Ofair --soft-time-limit 360 --time-limit 390 --loglevel INFO
|
||||
priority=4
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stdout_logfile={{ bench_dir }}/logs/worker.log
|
||||
stderr_logfile={{ bench_dir }}/logs/worker.error.log
|
||||
user={{ user }}
|
||||
stopwaitsecs=400
|
||||
directory={{ sites_dir }}
|
||||
killasgroup=true
|
||||
|
||||
[program:{{ bench_name }}-frappe-longjob-worker]
|
||||
command={{ bench_dir }}/env/bin/python -m frappe.celery_app worker -n longjobs@%%h -Ofair --soft-time-limit 1500 --time-limit 1530 --loglevel INFO
|
||||
priority=2
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stdout_logfile={{ bench_dir }}/logs/worker.log
|
||||
stderr_logfile={{ bench_dir }}/logs/worker.error.log
|
||||
user={{ user }}
|
||||
stopwaitsecs=1540
|
||||
directory={{ sites_dir }}
|
||||
killasgroup=true
|
||||
|
||||
[program:{{ bench_name }}-frappe-async-worker]
|
||||
command={{ bench_dir }}/env/bin/python -m frappe.celery_app worker -n async@%%h -Ofair --soft-time-limit 1500 --time-limit 1530 --loglevel INFO
|
||||
priority=2
|
||||
autostart=true
|
||||
autorestart=true
|
||||
stdout_logfile={{ bench_dir }}/logs/worker.log
|
||||
stderr_logfile={{ bench_dir }}/logs/worker.error.log
|
||||
user={{ user }}
|
||||
stopwaitsecs=1540
|
||||
directory={{ sites_dir }}
|
||||
killasgroup=true
|
||||
|
||||
{% endif %}
|
||||
|
||||
[program:{{ bench_name }}-redis-cache]
|
||||
command={{ redis_server }} {{ redis_cache_config }}
|
||||
priority=1
|
||||
@ -112,8 +163,17 @@ directory={{ bench_dir }}
|
||||
[group:{{ bench_name }}-web]
|
||||
programs={{ bench_name }}-frappe-web {%- if node -%} ,{{ bench_name }}-node-socketio {%- endif%}
|
||||
|
||||
{% if use_rq %}
|
||||
|
||||
[group:{{ bench_name }}-workers]
|
||||
programs={{ bench_name }}-frappe-schedule,{{ bench_name }}-frappe-default-worker,{{ bench_name }}-frappe-short-worker,{{ bench_name }}-frappe-long-worker
|
||||
|
||||
{% else %}
|
||||
|
||||
[group:{{ bench_name }}-workers]
|
||||
programs={{ bench_name }}-frappe-workerbeat,{{ bench_name }}-frappe-worker,{{ bench_name }}-frappe-longjob-worker,{{ bench_name }}-frappe-async-worker
|
||||
|
||||
{% endif %}
|
||||
|
||||
[group:{{ bench_name }}-redis]
|
||||
programs={{ bench_name }}-redis-cache,{{ bench_name }}-redis-queue {%- if frappe_version > 5 -%} ,{{ bench_name }}-redis-socketio {%- endif %}
|
||||
|
@ -18,7 +18,9 @@ def run(bench_path):
|
||||
if patch not in executed_patches:
|
||||
module = importlib.import_module(patch.split()[0])
|
||||
execute = getattr(module, 'execute')
|
||||
execute(bench_path)
|
||||
result = execute(bench_path)
|
||||
|
||||
if result != False:
|
||||
executed_patches.append(patch)
|
||||
|
||||
finally:
|
||||
|
@ -1,8 +1,17 @@
|
||||
import click, os
|
||||
from bench.config.procfile import setup_procfile
|
||||
from bench.config.supervisor import generate_supervisor_config
|
||||
from bench.app import get_current_frappe_version, get_current_branch
|
||||
|
||||
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'
|
||||
|
@ -271,18 +271,26 @@ def restart_supervisor_processes(bench='.'):
|
||||
from .config.common_site_config import get_config
|
||||
conf = get_config(bench=bench)
|
||||
bench_name = get_bench_name(bench)
|
||||
cmd = conf.get('supervisor_restart_cmd',
|
||||
'sudo supervisorctl restart {bench_name}-web: {bench_name}-workers:'.format(bench_name=bench_name))
|
||||
|
||||
try:
|
||||
cmd = conf.get('supervisor_restart_cmd')
|
||||
if cmd:
|
||||
exec_cmd(cmd, cwd=bench)
|
||||
|
||||
except CommandFailedError:
|
||||
if '{bench_name}-workers:'.format(bench_name=bench_name) in cmd:
|
||||
# backward compatibility
|
||||
exec_cmd('sudo supervisorctl restart frappe:', cwd=bench)
|
||||
else:
|
||||
raise
|
||||
supervisor_status = subprocess.check_output(['sudo', 'supervisorctl', 'status'], cwd=bench)
|
||||
|
||||
if '{bench_name}-workers:'.format(bench_name=bench_name) in supervisor_status:
|
||||
group = '{bench_name}-web: {bench_name}-workers:'.format(bench_name=bench_name)
|
||||
|
||||
# backward compatibility
|
||||
elif '{bench_name}-processes:'.format(bench_name=bench_name) in supervisor_status:
|
||||
group = '{bench_name}-processes:'.format(bench_name=bench_name)
|
||||
|
||||
# backward compatibility
|
||||
else:
|
||||
group = 'frappe:'
|
||||
|
||||
exec_cmd('sudo supervisorctl restart {group}'.format(group=group), cwd=bench)
|
||||
|
||||
def get_site_config(site, bench='.'):
|
||||
config_path = os.path.join(bench, 'sites', site, 'site_config.json')
|
||||
|
Loading…
Reference in New Issue
Block a user