2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-12 08:16:28 +00:00
bench/bench/cli.py

615 lines
20 KiB
Python
Raw Normal View History

2014-07-10 17:21:34 +00:00
import click
from .utils import init as _init
from .utils import setup_env as _setup_env
2015-08-14 10:11:53 +00:00
from .utils import new_site as _new_site
2014-07-11 04:29:57 +00:00
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
2014-07-15 09:18:50 +00:00
from .utils import start as _start
from .utils import setup_procfile as _setup_procfile
from .utils import set_nginx_port as _set_nginx_port
2014-11-19 07:09:37 +00:00
from .utils import set_url_root as _set_url_root
from .utils import set_default_site as _set_default_site
from .utils import (build_assets, patch_sites, exec_cmd, update_bench, get_env_cmd, get_frappe, setup_logging,
2014-11-10 15:51:45 +00:00
get_config, update_config, restart_supervisor_processes, put_config, default_config, update_requirements,
backup_all_sites, backup_site, get_sites, prime_wheel_cache, is_root, set_mariadb_host, drop_privileges,
2015-03-05 09:38:39 +00:00
fix_file_perms, fix_prod_setup_perms, set_ssl_certificate, set_ssl_certificate_key, get_cmd_output, post_upgrade,
2015-07-04 08:36:53 +00:00
pre_upgrade, PatchError, download_translations_p, setup_socketio)
2014-07-10 17:21:34 +00:00
from .app import get_app as _get_app
from .app import new_app as _new_app
from .app import pull_all_apps, get_apps, get_current_frappe_version, is_version_upgrade, switch_to_v4, switch_to_master, switch_to_develop
2015-07-04 08:36:53 +00:00
from .config import generate_nginx_config, generate_supervisor_config, generate_redis_cache_config, generate_redis_async_broker_config
2014-11-04 10:53:50 +00:00
from .production_setup import setup_production as _setup_production
2014-11-20 07:08:21 +00:00
from .migrate_to_v5 import migrate_to_v5
2014-07-10 17:21:34 +00:00
import os
2014-07-11 07:40:33 +00:00
import sys
2014-07-11 09:33:07 +00:00
import logging
2014-08-27 11:53:04 +00:00
import copy
2015-03-02 11:42:41 +00:00
import json
import pwd
2014-11-18 11:56:37 +00:00
import grp
2015-03-02 11:42:41 +00:00
import subprocess
2014-07-11 09:33:07 +00:00
logger = logging.getLogger('bench')
2014-07-11 07:40:33 +00:00
2015-03-03 11:04:35 +00:00
global FRAPPE_VERSION
2014-07-11 07:40:33 +00:00
def cli():
check_uid()
change_dir()
change_uid()
2014-07-15 06:17:36 +00:00
if len(sys.argv) > 2 and sys.argv[1] == "frappe":
2015-03-02 11:42:41 +00:00
return old_frappe_cli()
elif len(sys.argv) > 1 and sys.argv[1] in get_frappe_commands():
return frappe_cmd()
2015-03-05 11:04:28 +00:00
elif len(sys.argv) > 1 and sys.argv[1] in ("--site", "--verbose", "--force", "--profile"):
2015-03-02 11:42:41 +00:00
return frappe_cmd()
elif len(sys.argv) > 1 and sys.argv[1]=="--help":
print click.Context(bench).get_help()
print
print get_frappe_help()
2015-08-14 10:11:53 +00:00
return
2015-03-02 11:42:41 +00:00
elif len(sys.argv) > 1 and sys.argv[1] in get_apps():
return app_cmd()
2015-03-02 11:42:41 +00:00
else:
2015-05-11 15:21:17 +00:00
try:
bench()
except PatchError:
sys.exit(1)
2014-07-11 07:40:33 +00:00
2014-11-10 09:26:09 +00:00
def cmd_requires_root():
2014-11-10 11:39:05 +00:00
if len(sys.argv) > 2 and sys.argv[2] in ('production', 'sudoers'):
2014-11-10 09:26:09 +00:00
return True
if len(sys.argv) > 2 and sys.argv[1] in ('patch',):
return True
def check_uid():
2014-11-10 09:26:09 +00:00
if cmd_requires_root() and not is_root():
print 'superuser privileges required for this command'
sys.exit(1)
def change_uid():
2014-11-10 09:26:09 +00:00
if is_root() and not cmd_requires_root():
frappe_user = get_config().get('frappe_user')
if frappe_user:
2014-11-10 15:51:45 +00:00
drop_privileges(uid_name=frappe_user, gid_name=frappe_user)
2014-11-10 10:33:23 +00:00
os.environ['HOME'] = pwd.getpwnam(frappe_user).pw_dir
else:
print 'You should not run this command as root'
sys.exit(1)
def change_dir():
2015-03-09 13:42:10 +00:00
if os.path.exists('config.json') or "init" in sys.argv:
2015-01-29 13:50:49 +00:00
return
dir_path_file = '/etc/frappe_bench_dir'
if os.path.exists(dir_path_file):
with open(dir_path_file) as f:
dir_path = f.read().strip()
2014-12-03 05:04:23 +00:00
if os.path.exists(dir_path):
os.chdir(dir_path)
2015-03-02 11:42:41 +00:00
def old_frappe_cli(bench='.'):
2014-07-11 07:40:33 +00:00
f = get_frappe(bench=bench)
os.chdir(os.path.join(bench, 'sites'))
os.execv(f, [f] + sys.argv[2:])
2014-07-10 17:21:34 +00:00
def app_cmd(bench='.'):
f = get_env_cmd('python', bench=bench)
os.chdir(os.path.join(bench, 'sites'))
os.execv(f, [f] + ['-m', 'frappe.utils.bench_helper'] + sys.argv[1:])
2015-03-02 11:42:41 +00:00
def frappe_cmd(bench='.'):
f = get_env_cmd('python', bench=bench)
os.chdir(os.path.join(bench, 'sites'))
os.execv(f, [f] + ['-m', 'frappe.utils.bench_helper', 'frappe'] + sys.argv[1:])
def get_frappe_commands(bench='.'):
python = get_env_cmd('python', bench=bench)
sites_path = os.path.join(bench, 'sites')
2015-03-04 06:02:12 +00:00
if not os.path.exists(sites_path):
return []
2015-03-02 11:42:41 +00:00
try:
return json.loads(get_cmd_output("{python} -m frappe.utils.bench_helper get-frappe-commands".format(python=python), cwd=sites_path))
except subprocess.CalledProcessError:
return []
def get_frappe_help(bench='.'):
python = get_env_cmd('python', bench=bench)
sites_path = os.path.join(bench, 'sites')
2015-03-04 06:02:12 +00:00
if not os.path.exists(sites_path):
return []
2015-03-02 11:42:41 +00:00
try:
out = get_cmd_output("{python} -m frappe.utils.bench_helper get-frappe-help".format(python=python), cwd=sites_path)
return "Framework commands:\n" + out.split('Commands:')[1]
except subprocess.CalledProcessError:
return ""
2014-08-27 11:53:04 +00:00
@click.command()
def shell(bench='.'):
if not os.environ.get('SHELL'):
print "Cannot get shell"
sys.exit(1)
if not os.path.exists('sites'):
print "sites dir doesn't exist"
sys.exit(1)
env = copy.copy(os.environ)
env['PS1'] = '(' + os.path.basename(os.path.dirname(os.path.abspath(__file__))) + ')' + env.get('PS1', '')
env['PATH'] = os.path.dirname(os.path.abspath(os.path.join('env','bin')) + ':' + env['PATH'])
os.chdir('sites')
os.execve(env['SHELL'], [env['SHELL']], env)
2014-07-10 17:21:34 +00:00
@click.group()
2014-07-11 09:33:07 +00:00
def bench(bench='.'):
2014-07-15 06:54:44 +00:00
"Bench manager for Frappe"
2014-07-11 09:33:07 +00:00
# TODO add bench path context
2015-03-03 11:04:35 +00:00
global FRAPPE_VERSION
FRAPPE_VERSION = get_current_frappe_version()
2014-07-11 09:33:07 +00:00
setup_logging(bench=bench)
2014-07-10 17:21:34 +00:00
@click.command()
@click.argument('path')
2014-07-21 06:10:03 +00:00
@click.option('--apps_path', default=None, help="path to json files with apps to install after init")
2014-07-31 06:12:00 +00:00
@click.option('--frappe-path', default=None, help="path to frappe repo")
2014-09-12 09:30:18 +00:00
@click.option('--frappe-branch', default=None, help="path to frappe repo")
2014-07-31 06:12:00 +00:00
@click.option('--no-procfile', flag_value=True, type=bool, help="Pull changes in all the apps in bench")
@click.option('--no-backups',flag_value=True, type=bool, help="Run migrations for all sites in the bench")
@click.option('--no-auto-update',flag_value=True, type=bool, help="Build JS and CSS artifacts for the bench")
def init(path, apps_path, frappe_path, frappe_branch, no_procfile, no_backups,
2014-07-31 06:12:00 +00:00
no_auto_update):
2014-07-15 06:54:44 +00:00
"Create a new bench"
2014-07-31 06:12:00 +00:00
_init(path, apps_path=apps_path, no_procfile=no_procfile, no_backups=no_backups,
no_auto_update=no_auto_update, frappe_path=frappe_path, frappe_branch=frappe_branch)
2014-07-10 17:21:34 +00:00
click.echo('Bench {} initialized'.format(path))
@click.command('get-app')
@click.argument('name')
@click.argument('git-url')
2014-09-12 09:30:18 +00:00
@click.option('--branch', default=None, help="branch to checkout")
def get_app(name, git_url, branch):
2014-07-15 06:54:44 +00:00
"clone an app from the internet and set it up in your bench"
2014-09-12 09:30:18 +00:00
_get_app(name, git_url, branch=branch)
2015-08-14 10:11:53 +00:00
2014-07-10 17:21:34 +00:00
@click.command('new-app')
@click.argument('app-name')
def new_app(app_name):
2014-07-15 06:54:44 +00:00
"start a new app"
2014-07-10 17:21:34 +00:00
_new_app(app_name)
2015-08-14 10:11:53 +00:00
2014-07-10 17:21:34 +00:00
@click.command('new-site')
@click.option('--mariadb-root-password', help="MariaDB root password")
@click.option('--admin-password', help="admin password to set for site")
2014-07-10 17:21:34 +00:00
@click.argument('site')
def new_site(site, mariadb_root_password=None, admin_password=None):
2014-07-15 06:54:44 +00:00
"Create a new site in the bench"
_new_site(site, mariadb_root_password=mariadb_root_password, admin_password=admin_password)
2015-08-14 10:11:53 +00:00
#TODO: Not DRY
2014-07-10 17:21:34 +00:00
@click.command('update')
2014-07-15 06:54:44 +00:00
@click.option('--pull', flag_value=True, type=bool, help="Pull changes in all the apps in bench")
@click.option('--patch',flag_value=True, type=bool, help="Run migrations for all sites in the bench")
@click.option('--build',flag_value=True, type=bool, help="Build JS and CSS artifacts for the bench")
@click.option('--bench',flag_value=True, type=bool, help="Update bench")
2014-07-22 06:38:17 +00:00
@click.option('--requirements',flag_value=True, type=bool, help="Update requirements")
2014-07-15 06:54:44 +00:00
@click.option('--restart-supervisor',flag_value=True, type=bool, help="restart supervisor processes after update")
2014-07-15 06:17:36 +00:00
@click.option('--auto',flag_value=True, type=bool)
@click.option('--upgrade',flag_value=True, type=bool)
2014-09-03 07:19:30 +00:00
@click.option('--no-backup',flag_value=True, type=bool)
2015-07-04 08:36:53 +00:00
def _update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, upgrade=False):
2014-07-15 06:54:44 +00:00
"Update bench"
2014-07-22 06:38:17 +00:00
if not (pull or patch or build or bench or requirements):
pull, patch, build, bench, requirements = True, True, True, True, True
2014-07-15 06:17:36 +00:00
conf = get_config()
2015-07-04 08:36:53 +00:00
version_upgrade = is_version_upgrade()
if version_upgrade and not upgrade:
print
print
print "This update will cause a major version change in Frappe/ERPNext from {0} to {1} (beta).".format(*version_upgrade)
print "This would take significant time to migrate and might break custom apps. Please run `bench update --upgrade` to confirm."
2015-08-14 10:11:53 +00:00
print
2015-07-04 08:36:53 +00:00
# print "You can also pin your bench to {0} by running `bench swtich-to-v{0}`".format(version_upgrade[0])
print "You can stay on the latest stable release by running `bench switch-to-master` or pin your bench to {0} by running `bench swtich-to-v{0}`".format(version_upgrade[0])
sys.exit(1)
2014-09-05 09:23:21 +00:00
if conf.get('release_bench'):
print 'Release bench, cannot update'
sys.exit(1)
2015-07-04 08:36:53 +00:00
2014-09-17 06:29:12 +00:00
if auto:
2014-07-15 06:17:36 +00:00
sys.exit(1)
2015-07-04 08:36:53 +00:00
2014-07-15 06:17:36 +00:00
if bench and conf.get('update_bench_on_update'):
2014-07-11 04:32:54 +00:00
update_bench()
restart_update({
'pull': pull,
'patch': patch,
'build': build,
'requirements': requirements,
'no-backup': no_backup,
'restart-supervisor': restart_supervisor,
'upgrade': upgrade
})
2015-03-05 09:38:39 +00:00
2015-07-04 08:36:53 +00:00
update(pull, patch, build, bench, auto, restart_supervisor, requirements, no_backup, upgrade)
print "_"*80
print "https://frappe.io/buy - Donate to help make better free and open source tools"
print
2015-03-05 09:38:39 +00:00
2015-07-04 08:36:53 +00:00
def update(pull=False, patch=False, build=False, bench=False, auto=False, restart_supervisor=False, requirements=False, no_backup=False, upgrade=False, bench_path='.'):
conf = get_config(bench=bench_path)
version_upgrade = is_version_upgrade(bench=bench_path)
2015-03-05 11:04:28 +00:00
if version_upgrade and not upgrade:
2015-07-04 08:36:53 +00:00
raise Exception("Major Version Upgrade")
2015-03-05 09:38:39 +00:00
2014-07-10 17:21:34 +00:00
if pull:
2015-07-04 08:36:53 +00:00
pull_all_apps(bench=bench_path)
2015-03-05 09:38:39 +00:00
2015-05-26 08:28:00 +00:00
if requirements:
2015-07-04 08:36:53 +00:00
update_requirements(bench=bench_path)
2015-05-26 08:28:00 +00:00
2015-03-05 11:04:28 +00:00
if upgrade:
2015-07-04 08:36:53 +00:00
pre_upgrade(version_upgrade[0], version_upgrade[1], bench=bench_path)
2015-04-02 10:44:53 +00:00
import utils, app
reload(utils)
reload(app)
2014-07-10 17:21:34 +00:00
if patch:
2014-09-03 07:19:30 +00:00
if not no_backup:
2015-07-04 08:36:53 +00:00
backup_all_sites(bench=bench_path)
patch_sites(bench=bench_path)
2014-07-10 17:21:34 +00:00
if build:
2015-07-04 08:36:53 +00:00
build_assets(bench=bench_path)
2014-07-22 06:38:17 +00:00
if restart_supervisor or conf.get('restart_supervisor_on_update'):
2015-07-04 08:36:53 +00:00
restart_supervisor_processes(bench=bench_path)
2015-03-05 09:38:39 +00:00
if upgrade:
2015-07-04 08:36:53 +00:00
post_upgrade(version_upgrade[0], version_upgrade[1], bench=bench_path)
print "_"*80
2015-08-14 10:11:53 +00:00
print "Bench: Open source installer + admin for Frappe and ERPNext (https://erpnext.com)"
print
2014-07-11 04:29:57 +00:00
@click.command('retry-upgrade')
@click.option('--version', default=5)
def retry_upgrade(version):
pull_all_apps()
patch_sites()
build_assets()
post_upgrade(version-1, version)
def restart_update(kwargs):
args = ['--'+k for k, v in kwargs.items() if v]
os.execv(sys.argv[0], sys.argv[:2] + args)
2014-07-11 04:29:57 +00:00
@click.command('restart')
def restart():
2014-07-15 06:54:44 +00:00
"Restart supervisor processes"
2014-07-16 06:24:02 +00:00
restart_supervisor_processes()
2014-07-10 17:21:34 +00:00
2014-07-15 09:18:50 +00:00
@click.command('start')
@click.option('--no-dev', flag_value=True, type=bool)
def start(no_dev=False):
2014-07-15 09:18:50 +00:00
"Start Frappe development processes"
_start(no_dev=no_dev)
2014-07-15 09:18:50 +00:00
2014-07-17 09:38:26 +00:00
@click.command('migrate-3to4')
@click.argument('path')
def migrate_3to4(path):
"Migrate from ERPNext v3.x"
2014-07-21 10:45:32 +00:00
exec_cmd("{python} {migrate_3to4} {site}".format(
python=os.path.join('env', 'bin', 'python'),
migrate_3to4=os.path.join(os.path.dirname(__file__), 'migrate3to4.py'),
site=path))
2014-07-17 09:38:26 +00:00
@click.command('switch-to-master')
2015-05-04 04:12:25 +00:00
@click.option('--upgrade',flag_value=True, type=bool)
def _switch_to_master(upgrade=False):
"Switch frappe and erpnext to master branch"
2015-05-04 04:12:25 +00:00
switch_to_master(upgrade=upgrade)
2015-08-14 10:11:53 +00:00
print
print 'Switched to master'
print 'Please run `bench update --patch` to be safe from any differences in database schema'
@click.command('switch-to-develop')
2015-05-04 04:12:25 +00:00
@click.option('--upgrade',flag_value=True, type=bool)
def _switch_to_develop(upgrade=False):
"Switch frappe and erpnext to develop branch"
2015-05-04 04:12:25 +00:00
switch_to_develop(upgrade=upgrade)
2015-08-14 10:11:53 +00:00
print
print 'Switched to develop'
print 'Please run `bench update --patch` to be safe from any differences in database schema'
2015-08-14 10:11:53 +00:00
@click.command('switch-to-v4')
2015-05-04 04:12:25 +00:00
@click.option('--upgrade',flag_value=True, type=bool)
def _switch_to_v4(upgrade=False):
"Switch frappe and erpnext to v4 branch"
2015-05-04 04:12:25 +00:00
switch_to_v4(upgrade=upgrade)
2015-08-14 10:11:53 +00:00
print
print 'Switched to v4'
print 'Please run `bench update --patch` to be safe from any differences in database schema'
@click.command('set-nginx-port')
@click.argument('site')
@click.argument('port', type=int)
def set_nginx_port(site, port):
"Set nginx port for site"
_set_nginx_port(site, port)
2014-11-26 05:49:01 +00:00
@click.command('set-ssl-certificate')
@click.argument('site')
@click.argument('ssl-certificate-path')
def _set_ssl_certificate(site, ssl_certificate_path):
"Set ssl certificate path for site"
set_ssl_certificate(site, ssl_certificate_path)
@click.command('set-ssl-key')
@click.argument('site')
@click.argument('ssl-certificate-key-path')
def _set_ssl_certificate_key(site, ssl_certificate_key_path):
"Set ssl certificate private key path for site"
set_ssl_certificate_key(site, ssl_certificate_key_path)
2014-11-19 07:09:37 +00:00
@click.command('set-url-root')
@click.argument('site')
@click.argument('url-root')
def set_url_root(site, url_root):
"Set url root for site"
2014-11-19 07:17:15 +00:00
_set_url_root(site, url_root)
2014-11-19 07:09:37 +00:00
2014-11-07 14:49:13 +00:00
@click.command('set-mariadb-host')
@click.argument('host')
def _set_mariadb_host(host):
"Set MariaDB host for bench"
set_mariadb_host(host)
@click.command('set-default-site')
@click.argument('site')
def set_default_site(site):
"Set default site for bench"
_set_default_site(site)
2014-09-03 06:57:04 +00:00
@click.command('backup')
@click.argument('site')
def _backup_site(site):
"backup site"
if not site in get_sites(bench='.'):
print 'site not found'
sys.exit(1)
backup_site(site, bench='.')
@click.command('backup-all-sites')
def _backup_all_sites():
"backup all sites"
backup_all_sites(bench='.')
2014-09-04 07:38:43 +00:00
@click.command('prime-wheel-cache')
def _prime_wheel_cache():
"Update wheel cache"
prime_wheel_cache(bench='.')
2014-09-04 09:45:53 +00:00
@click.command('release')
@click.argument('app', type=click.Choice(['frappe', 'erpnext', 'shopping_cart']))
@click.argument('bump-type', type=click.Choice(['major', 'minor', 'patch']))
@click.option('--develop', default='develop')
@click.option('--master', default='master')
def _release(app, bump_type, develop, master):
2014-09-04 09:45:53 +00:00
"Release app (internal to the Frappe team)"
2014-09-05 04:00:54 +00:00
from .release import release
2014-09-04 09:45:53 +00:00
repo = os.path.join('apps', app)
release(repo, bump_type, develop, master)
2014-09-04 09:45:53 +00:00
2014-07-10 17:21:34 +00:00
## Setup
@click.group()
def setup():
2014-07-15 06:54:44 +00:00
"Setup bench"
2014-07-10 17:21:34 +00:00
pass
2015-08-14 10:11:53 +00:00
2014-07-10 17:21:34 +00:00
@click.command('sudoers')
2014-09-03 06:35:23 +00:00
@click.argument('user')
def setup_sudoers(user):
2014-07-15 06:54:44 +00:00
"Add commands to sudoers list for execution without password"
2014-09-03 06:35:23 +00:00
_setup_sudoers(user)
2015-08-14 10:11:53 +00:00
2014-07-10 17:21:34 +00:00
@click.command('nginx')
def setup_nginx():
2014-07-15 06:54:44 +00:00
"generate config for nginx"
generate_nginx_config()
2015-08-14 10:11:53 +00:00
2014-07-10 17:21:34 +00:00
@click.command('supervisor')
def setup_supervisor():
2014-07-15 06:54:44 +00:00
"generate config for supervisor"
generate_supervisor_config()
2015-08-14 10:11:53 +00:00
@click.command('redis-cache')
2015-02-24 09:40:30 +00:00
def setup_redis_cache():
"generate config for redis cache"
2015-07-04 08:36:53 +00:00
generate_redis_cache_config()
2015-08-14 10:11:53 +00:00
2015-07-04 08:36:53 +00:00
@click.command('redis-async-broker')
def setup_redis_async_broker():
"generate config for redis async broker"
generate_redis_async_broker_config()
2015-08-14 10:11:53 +00:00
2014-11-04 10:53:50 +00:00
@click.command('production')
2014-11-18 10:37:46 +00:00
@click.argument('user')
def setup_production(user):
2014-11-04 10:53:50 +00:00
"setup bench for production"
2014-11-18 10:37:46 +00:00
_setup_production(user=user)
2014-07-10 17:21:34 +00:00
@click.command('auto-update')
def setup_auto_update():
2014-07-15 06:54:44 +00:00
"Add cronjob for bench auto update"
2014-07-11 04:29:57 +00:00
_setup_auto_update()
2015-08-14 10:11:53 +00:00
2014-07-10 17:21:34 +00:00
@click.command('backups')
def setup_backups():
2014-07-15 06:54:44 +00:00
"Add cronjob for bench backups"
2014-07-11 04:29:57 +00:00
_setup_backups()
2014-07-10 17:21:34 +00:00
@click.command('dnsmasq')
def setup_dnsmasq():
pass
@click.command('env')
def setup_env():
2014-07-15 06:54:44 +00:00
"Setup virtualenv for bench"
2014-07-10 17:21:34 +00:00
_setup_env()
2014-07-15 09:18:50 +00:00
@click.command('procfile')
2015-07-04 08:36:53 +00:00
@click.option('--with-watch', flag_value=True, type=bool)
@click.option('--with-celery-broker', flag_value=True, type=bool)
def setup_procfile(with_celery_broker, with_watch):
2014-07-15 09:18:50 +00:00
"Setup Procfile for bench start"
2015-07-04 08:36:53 +00:00
_setup_procfile(with_celery_broker, with_watch)
@click.command('socketio')
def _setup_socketio():
"Setup node deps for socketio server"
setup_socketio()
2014-07-15 09:18:50 +00:00
2014-07-21 09:41:32 +00:00
@click.command('config')
def setup_config():
"overwrite or make config.json"
put_config(default_config)
2014-07-10 17:21:34 +00:00
setup.add_command(setup_nginx)
setup.add_command(setup_sudoers)
setup.add_command(setup_supervisor)
2015-02-24 09:40:30 +00:00
setup.add_command(setup_redis_cache)
2015-07-04 08:36:53 +00:00
setup.add_command(setup_redis_async_broker)
2014-07-10 17:21:34 +00:00
setup.add_command(setup_auto_update)
setup.add_command(setup_dnsmasq)
setup.add_command(setup_backups)
setup.add_command(setup_env)
2014-07-15 09:18:50 +00:00
setup.add_command(setup_procfile)
2015-07-04 08:36:53 +00:00
setup.add_command(_setup_socketio)
2014-07-21 09:41:32 +00:00
setup.add_command(setup_config)
2014-11-04 10:57:56 +00:00
setup.add_command(setup_production)
2014-07-10 17:21:34 +00:00
2014-07-15 06:17:36 +00:00
## Config
## Not DRY
@click.group()
def config():
2014-07-15 06:54:44 +00:00
"change bench configuration"
2014-07-15 06:17:36 +00:00
pass
@click.command('auto_update')
@click.argument('state', type=click.Choice(['on', 'off']))
def config_auto_update(state):
2014-07-15 06:54:44 +00:00
"Enable/Disable auto update for bench"
2014-07-15 06:17:36 +00:00
state = True if state == 'on' else False
update_config({'auto_update': state})
@click.command('restart_supervisor_on_update')
@click.argument('state', type=click.Choice(['on', 'off']))
def config_restart_supervisor_on_update(state):
2014-07-15 06:54:44 +00:00
"Enable/Disable auto restart of supervisor processes"
2014-07-15 06:17:36 +00:00
state = True if state == 'on' else False
update_config({'restart_supervisor_on_update': state})
@click.command('update_bench_on_update')
@click.argument('state', type=click.Choice(['on', 'off']))
def config_update_bench_on_update(state):
2014-07-15 06:54:44 +00:00
"Enable/Disable bench updates on running bench update"
2014-07-15 06:17:36 +00:00
state = True if state == 'on' else False
update_config({'update_bench_on_update': state})
@click.command('dns_multitenant')
@click.argument('state', type=click.Choice(['on', 'off']))
def config_dns_multitenant(state):
"Enable/Disable bench updates on running bench update"
state = True if state == 'on' else False
update_config({'dns_multitenant': state})
@click.command('serve_default_site')
@click.argument('state', type=click.Choice(['on', 'off']))
def config_serve_default_site(state):
"Configure nginx to serve the default site on port 80"
state = True if state == 'on' else False
update_config({'serve_default_site': state})
@click.command('rebase_on_pull')
@click.argument('state', type=click.Choice(['on', 'off']))
def config_rebase_on_pull(state):
"Rebase repositories on pulling"
state = True if state == 'on' else False
update_config({'rebase_on_pull': state})
2014-09-04 10:05:23 +00:00
@click.command('http_timeout')
@click.argument('seconds', type=int)
def config_http_timeout(seconds):
"set http timeout"
update_config({'http_timeout': seconds})
2014-07-15 06:17:36 +00:00
config.add_command(config_auto_update)
config.add_command(config_update_bench_on_update)
config.add_command(config_restart_supervisor_on_update)
config.add_command(config_dns_multitenant)
config.add_command(config_serve_default_site)
2014-09-04 10:05:23 +00:00
config.add_command(config_http_timeout)
2014-07-15 06:17:36 +00:00
2014-10-13 04:54:07 +00:00
@click.group()
def patch():
pass
2015-01-29 13:50:49 +00:00
@click.command('fix-prod-perms')
def _fix_prod_perms():
"Fix permissions if supervisor processes were run as root"
2014-11-18 12:03:36 +00:00
if os.path.exists("config/supervisor.conf"):
exec_cmd("supervisorctl stop frappe:")
2015-01-29 13:50:49 +00:00
fix_prod_setup_perms()
2014-11-18 11:56:37 +00:00
2014-11-18 12:03:36 +00:00
if os.path.exists("config/supervisor.conf"):
exec_cmd("{bench} setup supervisor".format(bench=sys.argv[0]))
exec_cmd("supervisorctl reload")
2014-11-18 11:56:37 +00:00
2015-01-29 13:50:49 +00:00
@click.command('fix-file-perms')
def _fix_file_perms():
"Fix file permissions"
fix_file_perms()
patch.add_command(_fix_file_perms)
patch.add_command(_fix_prod_perms)
2014-10-13 04:54:07 +00:00
2015-05-26 08:28:00 +00:00
@click.command('download-translations')
def _download_translations():
"Download latest translations"
download_translations_p()
2014-07-10 17:21:34 +00:00
#Bench commands
bench.add_command(init)
bench.add_command(get_app)
bench.add_command(new_app)
bench.add_command(new_site)
bench.add_command(setup)
2015-07-04 08:36:53 +00:00
bench.add_command(_update)
2014-07-11 04:29:57 +00:00
bench.add_command(restart)
2014-07-15 06:17:36 +00:00
bench.add_command(config)
2014-07-15 09:18:50 +00:00
bench.add_command(start)
bench.add_command(set_nginx_port)
2014-11-26 05:49:01 +00:00
bench.add_command(_set_ssl_certificate)
bench.add_command(_set_ssl_certificate_key)
2014-11-07 14:49:13 +00:00
bench.add_command(_set_mariadb_host)
bench.add_command(set_default_site)
2014-07-17 09:38:26 +00:00
bench.add_command(migrate_3to4)
bench.add_command(_switch_to_master)
bench.add_command(_switch_to_develop)
bench.add_command(_switch_to_v4)
2014-08-27 11:53:04 +00:00
bench.add_command(shell)
2014-09-03 06:57:04 +00:00
bench.add_command(_backup_all_sites)
bench.add_command(_backup_site)
2014-09-04 07:38:43 +00:00
bench.add_command(_prime_wheel_cache)
2014-09-04 09:45:53 +00:00
bench.add_command(_release)
2014-10-13 04:54:07 +00:00
bench.add_command(patch)
2014-11-19 07:09:37 +00:00
bench.add_command(set_url_root)
bench.add_command(retry_upgrade)
2015-05-26 08:28:00 +00:00
bench.add_command(_download_translations)