mirror of
https://github.com/frappe/bench.git
synced 2024-11-12 00:06:36 +00:00
Merge branch 'develop' into bump-node-v12
This commit is contained in:
commit
b02b034a78
@ -43,6 +43,7 @@ def reload_nginx():
|
|||||||
@click.option("--user", help="optional user argument")
|
@click.option("--user", help="optional user argument")
|
||||||
@click.option("--yes", help="Yes to regeneration of supervisor config", is_flag=True, default=False)
|
@click.option("--yes", help="Yes to regeneration of supervisor config", is_flag=True, default=False)
|
||||||
def setup_supervisor(user=None, yes=False):
|
def setup_supervisor(user=None, yes=False):
|
||||||
|
bench.config.supervisor.update_supervisord_config(user=user, yes=yes)
|
||||||
bench.config.supervisor.generate_supervisor_config(bench_path=".", user=user, yes=yes)
|
bench.config.supervisor.generate_supervisor_config(bench_path=".", user=user, yes=yes)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
# imports - standard imports
|
# imports - standard imports
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# imports - module imports
|
# imports - module imports
|
||||||
|
import bench
|
||||||
from bench.config.common_site_config import get_config
|
from bench.config.common_site_config import get_config
|
||||||
from bench.config.nginx import make_nginx_conf
|
from bench.config.nginx import make_nginx_conf
|
||||||
from bench.config.supervisor import generate_supervisor_config
|
from bench.config.supervisor import generate_supervisor_config, update_supervisord_config
|
||||||
from bench.config.systemd import generate_systemd_config
|
from bench.config.systemd import generate_systemd_config
|
||||||
from bench.utils import CommandFailedError, exec_cmd, find_executable, fix_prod_setup_perms, get_bench_name, get_cmd_output
|
from bench.utils import CommandFailedError, exec_cmd, find_executable, fix_prod_setup_perms, get_bench_name, get_cmd_output, log
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(bench.PROJECT_NAME)
|
||||||
|
|
||||||
|
|
||||||
def setup_production_prerequisites():
|
def setup_production_prerequisites():
|
||||||
@ -23,14 +28,20 @@ def setup_production_prerequisites():
|
|||||||
|
|
||||||
|
|
||||||
def setup_production(user, bench_path='.', yes=False):
|
def setup_production(user, bench_path='.', yes=False):
|
||||||
|
print("Setting Up prerequisites...")
|
||||||
setup_production_prerequisites()
|
setup_production_prerequisites()
|
||||||
if get_config(bench_path).get('restart_supervisor_on_update') and get_config(bench_path).get('restart_systemd_on_update'):
|
if get_config(bench_path).get('restart_supervisor_on_update') and get_config(bench_path).get('restart_systemd_on_update'):
|
||||||
raise Exception("You cannot use supervisor and systemd at the same time. Modify your common_site_config accordingly." )
|
raise Exception("You cannot use supervisor and systemd at the same time. Modify your common_site_config accordingly." )
|
||||||
|
|
||||||
if get_config(bench_path).get('restart_systemd_on_update'):
|
if get_config(bench_path).get('restart_systemd_on_update'):
|
||||||
|
print("Setting Up systemd...")
|
||||||
generate_systemd_config(bench_path=bench_path, user=user, yes=yes)
|
generate_systemd_config(bench_path=bench_path, user=user, yes=yes)
|
||||||
else:
|
else:
|
||||||
|
print("Setting Up supervisor...")
|
||||||
|
update_supervisord_config(user=user, yes=yes)
|
||||||
generate_supervisor_config(bench_path=bench_path, user=user, yes=yes)
|
generate_supervisor_config(bench_path=bench_path, user=user, yes=yes)
|
||||||
|
|
||||||
|
print("Setting Up NGINX...")
|
||||||
make_nginx_conf(bench_path=bench_path, yes=yes)
|
make_nginx_conf(bench_path=bench_path, yes=yes)
|
||||||
fix_prod_setup_perms(bench_path, frappe_user=user)
|
fix_prod_setup_perms(bench_path, frappe_user=user)
|
||||||
remove_default_nginx_configs()
|
remove_default_nginx_configs()
|
||||||
@ -38,6 +49,7 @@ def setup_production(user, bench_path='.', yes=False):
|
|||||||
bench_name = get_bench_name(bench_path)
|
bench_name = get_bench_name(bench_path)
|
||||||
nginx_conf = '/etc/nginx/conf.d/{bench_name}.conf'.format(bench_name=bench_name)
|
nginx_conf = '/etc/nginx/conf.d/{bench_name}.conf'.format(bench_name=bench_name)
|
||||||
|
|
||||||
|
print("Setting Up symlinks and reloading services...")
|
||||||
if get_config(bench_path).get('restart_supervisor_on_update'):
|
if get_config(bench_path).get('restart_supervisor_on_update'):
|
||||||
supervisor_conf_extn = "ini" if is_centos7() else "conf"
|
supervisor_conf_extn = "ini" if is_centos7() else "conf"
|
||||||
supervisor_conf = os.path.join(get_supervisor_confdir(), '{bench_name}.{extn}'.format(
|
supervisor_conf = os.path.join(get_supervisor_confdir(), '{bench_name}.{extn}'.format(
|
||||||
@ -100,7 +112,7 @@ def service(service_name, service_option):
|
|||||||
exec_cmd(service_manager_command)
|
exec_cmd(service_manager_command)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception('No service manager found')
|
log("No service manager found: '{0} {1}' failed to execute".format(service_name, service_option), level=2)
|
||||||
|
|
||||||
|
|
||||||
def get_supervisor_confdir():
|
def get_supervisor_confdir():
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# imports - standard imports
|
# imports - standard imports
|
||||||
import getpass
|
import getpass
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# imports - module imports
|
# imports - module imports
|
||||||
@ -13,13 +14,14 @@ import click
|
|||||||
from six.moves import configparser
|
from six.moves import configparser
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(bench.PROJECT_NAME)
|
||||||
|
|
||||||
|
|
||||||
def generate_supervisor_config(bench_path, user=None, yes=False):
|
def generate_supervisor_config(bench_path, user=None, yes=False):
|
||||||
"""Generate supervisor config for respective bench path"""
|
"""Generate supervisor config for respective bench path"""
|
||||||
if not user:
|
if not user:
|
||||||
user = getpass.getuser()
|
user = getpass.getuser()
|
||||||
|
|
||||||
update_supervisord_conf(user=user)
|
|
||||||
|
|
||||||
template = bench.config.env.get_template('supervisor.conf')
|
template = bench.config.env.get_template('supervisor.conf')
|
||||||
config = get_config(bench_path=bench_path)
|
config = get_config(bench_path=bench_path)
|
||||||
bench_dir = os.path.abspath(bench_path)
|
bench_dir = os.path.abspath(bench_path)
|
||||||
@ -64,14 +66,23 @@ def get_supervisord_conf():
|
|||||||
return possibility
|
return possibility
|
||||||
|
|
||||||
|
|
||||||
def update_supervisord_conf(user):
|
def update_supervisord_config(user=None, yes=False):
|
||||||
"""From bench v5.0, we're moving to supervisor running as user"""
|
"""From bench v5.x, we're moving to supervisor running as user"""
|
||||||
from bench.config.production_setup import service
|
from bench.config.production_setup import service
|
||||||
|
|
||||||
|
if not user:
|
||||||
|
user = getpass.getuser()
|
||||||
|
|
||||||
supervisord_conf = get_supervisord_conf()
|
supervisord_conf = get_supervisord_conf()
|
||||||
section = "unix_http_server"
|
section = "unix_http_server"
|
||||||
|
updated_values = {
|
||||||
|
"chmod": "0760",
|
||||||
|
"chown": "{user}:{user}".format(user=user)
|
||||||
|
}
|
||||||
|
supervisord_conf_changes = ""
|
||||||
|
|
||||||
if not supervisord_conf:
|
if not supervisord_conf:
|
||||||
|
logger.log("supervisord.conf not found")
|
||||||
return
|
return
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
@ -79,12 +90,35 @@ def update_supervisord_conf(user):
|
|||||||
|
|
||||||
if section not in config.sections():
|
if section not in config.sections():
|
||||||
config.add_section(section)
|
config.add_section(section)
|
||||||
|
action = "Section {0} Added".format(section)
|
||||||
|
logger.log(action)
|
||||||
|
supervisord_conf_changes += '\n' + action
|
||||||
|
|
||||||
config.set(section, "chmod", "0760")
|
for key, value in updated_values.items():
|
||||||
config.set(section, "chown", "{user}:{user}".format(user=user))
|
try:
|
||||||
|
current_value = config.get(section, key)
|
||||||
|
except configparser.NoOptionError:
|
||||||
|
current_value = ""
|
||||||
|
|
||||||
with open(supervisord_conf, "w") as f:
|
if current_value.strip() != value:
|
||||||
config.write(f)
|
config.set(section, key, value)
|
||||||
|
action = "Updated supervisord.conf: '{0}' changed from '{1}' to '{2}'".format(key, current_value, value)
|
||||||
|
logger.log(action)
|
||||||
|
supervisord_conf_changes += '\n' + action
|
||||||
|
|
||||||
# restart supervisor to take new changes into effect
|
if not supervisord_conf_changes:
|
||||||
service('supervisor', 'restart')
|
logger.log("supervisord.conf not updated")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not yes:
|
||||||
|
click.confirm("{0} will be updated with the following values:\n{1}\nDo you want to continue?".format(supervisord_conf, supervisord_conf_changes), abort=True)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(supervisord_conf, "w") as f:
|
||||||
|
config.write(f)
|
||||||
|
logger.log("Updated supervisord.conf at '{0}'".format(supervisord_conf))
|
||||||
|
except Exception as e:
|
||||||
|
logger.log("Updating supervisord.conf failed due to '{0}'".format(e))
|
||||||
|
|
||||||
|
# Reread supervisor configuration, reload supervisord and supervisorctl, restart services that were started
|
||||||
|
service('supervisor', 'reload')
|
||||||
|
@ -19,7 +19,7 @@ class TestSetupProduction(TestBenchBase):
|
|||||||
for bench_name in ("test-bench-1", "test-bench-2"):
|
for bench_name in ("test-bench-1", "test-bench-2"):
|
||||||
bench_path = os.path.join(os.path.abspath(self.benches_path), bench_name)
|
bench_path = os.path.join(os.path.abspath(self.benches_path), bench_name)
|
||||||
self.init_bench(bench_name)
|
self.init_bench(bench_name)
|
||||||
bench.utils.exec_cmd("sudo bench setup production {0}".format(user), cwd=bench_path)
|
bench.utils.exec_cmd("sudo bench setup production {0} --yes".format(user), cwd=bench_path)
|
||||||
self.assert_nginx_config(bench_name)
|
self.assert_nginx_config(bench_name)
|
||||||
self.assert_supervisor_config(bench_name)
|
self.assert_supervisor_config(bench_name)
|
||||||
self.assert_supervisor_process(bench_name)
|
self.assert_supervisor_process(bench_name)
|
||||||
|
Loading…
Reference in New Issue
Block a user