2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-11 15:51:03 +00:00
* Generate common_site_config.json while initializing a new bench
* Clean-up some code
This commit is contained in:
shreyas 2016-02-25 14:12:44 +05:30 committed by Anand Doshi
parent a12cffacca
commit 2a4665ca37
8 changed files with 48 additions and 21 deletions

View File

@ -54,7 +54,7 @@ def get_app(app, git_url, branch=None, bench='.', build_asset_files=True, verbos
install_app(app, bench=bench, verbose=verbose)
if build_asset_files:
build_assets(bench=bench)
conf = get_config()
conf = get_config(bench=bench)
if conf.get('restart_supervisor_on_update'):
restart_supervisor_processes(bench=bench)

View File

@ -30,7 +30,7 @@ def generate_supervisor_config(bench='.', user=None):
sites = get_sites(bench=bench)
if not user:
user = getpass.getuser()
config = get_config()
config = get_config(bench=bench)
config = template.render(**{
"bench_dir": bench_dir,
@ -52,6 +52,30 @@ def get_site_config(site, bench='.'):
with open(os.path.join(bench, 'sites', site, 'site_config.json')) as f:
return json.load(f)
def generate_common_site_config(bench='.'):
'''Generates the default common_site_config.json while a new bench is created'''
config = get_config(bench=bench)
celery_broker_port = config.get('redis_celery_broker_port', '11311')
celery_broker = 'redis://localhost:{0}'.format(celery_broker_port)
async_redis_server_port = config.get('redis_async_broker_port', '12311')
async_redis_server = 'redis://localhost:{0}'.format(async_redis_server_port)
cache_redis_server_port = config.get('redis_cache_port', '13311')
cache_redis_server = 'redis://localhost:{0}'.format(cache_redis_server_port)
default_common_site_config = {
"celery_broker" : celery_broker,
"async_redis_server": async_redis_server,
"cache_redis_server": cache_redis_server
}
#TODO Optionally we need to add the host or domain name in case dns_multitenant is false
with open(os.path.join(bench, 'sites', 'common_site_config.json'), 'wb') as f:
json.dump(default_common_site_config, f, indent=1, sort_keys=True)
def get_sites_with_config(bench='.'):
sites = get_sites(bench=bench)
ret = []
@ -71,8 +95,9 @@ def generate_nginx_config(bench='.'):
sites_dir = os.path.join(bench_dir, "sites")
sites = get_sites_with_config(bench=bench)
user = getpass.getuser()
config = get_config(bench)
if get_config().get('serve_default_site'):
if config.get('serve_default_site'):
try:
with open("sites/currentsite.txt") as f:
default_site = {'name': f.read().strip()}
@ -83,9 +108,9 @@ def generate_nginx_config(bench='.'):
config = template.render(**{
"sites_dir": sites_dir,
"http_timeout": get_config().get("http_timeout", 120),
"http_timeout": config.get("http_timeout", 120),
"default_site": default_site,
"dns_multitenant": get_config().get('dns_multitenant'),
"dns_multitenant": config.get('dns_multitenant'),
"sites": sites
})
write_config_file(bench, 'nginx.conf', config)
@ -95,7 +120,7 @@ def generate_redis_celery_broker_config(bench='.'):
_generate_redis_config(
template_name='redis_celery_broker.conf',
context={
"port": get_config().get('redis_async_broker_port', '12311'),
"port": get_config(bench).get('redis_celery_broker_port', '11311'),
"bench_path": os.path.abspath(bench),
},
bench=bench
@ -106,21 +131,21 @@ def generate_redis_async_broker_config(bench='.'):
_generate_redis_config(
template_name='redis_async_broker.conf',
context={
"port": get_config().get('redis_async_broker_port', '12311'),
"bench_path": os.path.abspath(bench)
"port": get_config(bench).get('redis_async_broker_port', '12311'),
},
bench=bench
)
def generate_redis_cache_config(bench='.'):
"""Redis that is used and optimized for caching"""
config = get_config(bench=bench)
_generate_redis_config(
template_name='redis_cache.conf',
context={
"maxmemory": get_config().get('cache_maxmemory', '50'),
"port": get_config().get('redis_cache_port', '11311'),
"maxmemory": config.get('cache_maxmemory', '50'),
"port": config.get('redis_cache_port', '13311'),
"redis_version": get_redis_version(),
"bench_path": os.path.abspath(bench),
},
bench=bench
)

View File

@ -52,7 +52,7 @@ def copy_default_nginx_config():
def setup_production(user, bench='.'):
generate_supervisor_config(bench=bench, user=user)
generate_nginx_config(bench=bench)
fix_prod_setup_perms(frappe_user=user)
fix_prod_setup_perms(bench, frappe_user=user)
remove_default_nginx_configs()
if is_centos7():

View File

@ -2,4 +2,3 @@ dbfilename redis_async_broker.rdb
dir {{process_files_path}}
pidfile {{process_files_path}}/redis_async_broker.pid
port {{port}}
bench_path {{bench_path}}

View File

@ -6,4 +6,3 @@ maxmemory {{maxmemory}}mb
maxmemory-policy allkeys-lru
save ""
appendonly no
bench_path {{bench_path}}

View File

@ -2,4 +2,3 @@ dbfilename redis_celery_broker.rdb
dir {{process_files_path}}
pidfile {{process_files_path}}/redis_celery_broker.pid
port {{port}}
bench_path {{bench_path}}

View File

@ -103,5 +103,8 @@ class TestBenchInit(unittest.TestCase):
for key, port in ports:
self.assertEqual(config_json.get(key), port)
def assert_site_config(self, bench_name):
pass
def assert_exists(self, *args):
self.assertTrue(os.path.exists(os.path.join(*args)))

View File

@ -49,7 +49,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
no_auto_update=False, frappe_path=None, frappe_branch=None, wheel_cache_dir=None,
verbose=False):
from .app import get_app, install_apps_from_path
from .config import generate_redis_cache_config, generate_redis_async_broker_config, generate_redis_celery_broker_config
from .config import generate_redis_cache_config, generate_redis_async_broker_config, generate_redis_celery_broker_config, generate_common_site_config
global FRAPPE_VERSION
if os.path.exists(path):
@ -68,6 +68,8 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
bench_config = make_bench_config()
put_config(bench_config, bench=path)
generate_common_site_config(bench=path)
if not frappe_path:
frappe_path = 'https://github.com/frappe/frappe.git'
get_app('frappe', frappe_path, branch=frappe_branch, bench=path, build_asset_files=False, verbose=verbose)
@ -100,8 +102,8 @@ def make_bench_config():
return bench_config
def get_max_worker_count():
'''This function will return the maximum workers that can be started depending upon'''
'''number of cpu's present on the machine'''
'''This function will return the maximum workers that can be started depending upon
number of cpu's present on the machine'''
n_cpus = multiprocessing.cpu_count()
return dict(max_workers=2 * n_cpus)
@ -291,7 +293,7 @@ def setup_logging(bench='.'):
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)
def get_config(bench='.'):
def get_config(bench):
config_path = os.path.join(bench, 'config.json')
if not os.path.exists(config_path):
return {}
@ -473,7 +475,7 @@ def drop_privileges(uid_name='nobody', gid_name='nogroup'):
# Ensure a very conservative umask
os.umask(022)
def fix_prod_setup_perms(frappe_user=None):
def fix_prod_setup_perms(bench='.', frappe_user=None):
files = [
"logs/web.error.log",
"logs/web.log",
@ -486,7 +488,7 @@ def fix_prod_setup_perms(frappe_user=None):
]
if not frappe_user:
frappe_user = get_config().get('frappe_user')
frappe_user = get_config(bench).get('frappe_user')
if not frappe_user:
print "frappe user not set"