mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 08:30:39 +00:00
Add bench start, fix #7
This commit is contained in:
parent
70c9d65da5
commit
65560034b7
14
bench/cli.py
14
bench/cli.py
@ -5,6 +5,8 @@ from .utils import new_site as _new_site
|
||||
from .utils import setup_backups as _setup_backups
|
||||
from .utils import setup_auto_update as _setup_auto_update
|
||||
from .utils import setup_sudoers as _setup_sudoers
|
||||
from .utils import start as _start
|
||||
from .utils import setup_procfile as _setup_procfile
|
||||
from .utils import build_assets, patch_sites, exec_cmd, update_bench, get_frappe, setup_logging, get_config, update_config
|
||||
from .app import get_app as _get_app
|
||||
from .app import new_app as _new_app
|
||||
@ -89,6 +91,11 @@ def restart():
|
||||
"Restart supervisor processes"
|
||||
exec_cmd("sudo supervisorctl restart frappe:")
|
||||
|
||||
@click.command('start')
|
||||
def start():
|
||||
"Start Frappe development processes"
|
||||
_start()
|
||||
|
||||
## Setup
|
||||
@click.group()
|
||||
def setup():
|
||||
@ -129,6 +136,11 @@ def setup_env():
|
||||
"Setup virtualenv for bench"
|
||||
_setup_env()
|
||||
|
||||
@click.command('procfile')
|
||||
def setup_procfile():
|
||||
"Setup Procfile for bench start"
|
||||
_setup_procfile()
|
||||
|
||||
setup.add_command(setup_nginx)
|
||||
setup.add_command(setup_sudoers)
|
||||
setup.add_command(setup_supervisor)
|
||||
@ -136,6 +148,7 @@ setup.add_command(setup_auto_update)
|
||||
setup.add_command(setup_dnsmasq)
|
||||
setup.add_command(setup_backups)
|
||||
setup.add_command(setup_env)
|
||||
setup.add_command(setup_procfile)
|
||||
|
||||
## Config
|
||||
## Not DRY
|
||||
@ -179,4 +192,5 @@ bench.add_command(setup)
|
||||
bench.add_command(update)
|
||||
bench.add_command(restart)
|
||||
bench.add_command(config)
|
||||
bench.add_command(start)
|
||||
|
||||
|
@ -4,6 +4,7 @@ import subprocess
|
||||
import getpass
|
||||
import logging
|
||||
import json
|
||||
from distutils.spawn import find_executable
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -35,6 +36,7 @@ def init(path):
|
||||
setup_env(bench=path)
|
||||
put_config(default_config, bench=path)
|
||||
get_app('frappe', 'https://github.com/frappe/frappe.git', bench=path)
|
||||
setup_procfile(bench=path)
|
||||
setup_backups(bench=path)
|
||||
setup_auto_update(bench=path)
|
||||
|
||||
@ -48,6 +50,12 @@ def exec_cmd(cmd, cwd='.'):
|
||||
def setup_env(bench='.'):
|
||||
exec_cmd('virtualenv {} -p {}'.format('env', sys.executable), cwd=bench)
|
||||
|
||||
def setup_procfile(bench='.'):
|
||||
with open(os.path.join(bench, 'Procfile'), 'w') as f:
|
||||
f.write("""web: ./env/bin/frappe --serve --sites_path sites
|
||||
worker: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app worker'
|
||||
workerbeat: sh -c 'cd sites && exec ../env/bin/python -m frappe.celery_app beat -s scheduler.schedule'""")
|
||||
|
||||
def new_site(site, bench='.'):
|
||||
logger.info('creating new site {}'.format(site))
|
||||
exec_cmd("{frappe} --install {site} {site}".format(frappe=get_frappe(bench=bench), site=site), cwd=os.path.join(bench, 'sites'))
|
||||
@ -115,3 +123,25 @@ def update_config(new_config, bench='.'):
|
||||
config = get_config(bench=bench)
|
||||
config.update(new_config)
|
||||
put_config(config, bench=bench)
|
||||
|
||||
def get_process_manager():
|
||||
programs = ['foreman', 'forego', 'honcho']
|
||||
program = None
|
||||
for p in programs:
|
||||
program = find_executable(p)
|
||||
if program:
|
||||
break
|
||||
return program
|
||||
|
||||
def start():
|
||||
program = get_process_manager()
|
||||
if not program:
|
||||
raise Exception("No process manager found")
|
||||
os.execv(program, [program, 'start'])
|
||||
|
||||
def check_cmd(cmd, cwd='.'):
|
||||
try:
|
||||
subprocess.check_call(cmd, cwd=cwd, shell=True)
|
||||
return True
|
||||
except subprocess.CalledProcessError, e:
|
||||
return False
|
||||
|
Loading…
Reference in New Issue
Block a user