mirror of
https://github.com/frappe/bench.git
synced 2025-01-25 07:58:24 +00:00
chore: optimized and removed deprecated api usage and imports
This commit is contained in:
parent
39f8223d6d
commit
d2a70badd3
@ -1,12 +1,15 @@
|
|||||||
from bench.utils import get_program, exec_cmd, get_cmd_output, fix_prod_setup_perms, get_bench_name, find_executable, CommandFailedError
|
# imports - standard imports
|
||||||
from bench.config.supervisor import generate_supervisor_config
|
import os
|
||||||
from bench.config.systemd import generate_systemd_config
|
|
||||||
from bench.config.nginx import make_nginx_conf
|
|
||||||
from bench.config.common_site_config import get_config
|
|
||||||
import os, subprocess
|
|
||||||
import sys
|
import sys
|
||||||
from distutils.spawn import find_executable
|
from distutils.spawn import find_executable
|
||||||
|
|
||||||
|
# imports - module imports
|
||||||
|
from bench.config.common_site_config import get_config
|
||||||
|
from bench.config.nginx import make_nginx_conf
|
||||||
|
from bench.config.supervisor import generate_supervisor_config
|
||||||
|
from bench.config.systemd import generate_systemd_config
|
||||||
|
from bench.utils import CommandFailedError, exec_cmd, fix_prod_setup_perms, get_bench_name, get_cmd_output
|
||||||
|
|
||||||
|
|
||||||
def setup_production_prerequisites():
|
def setup_production_prerequisites():
|
||||||
if not find_executable("ansible"):
|
if not find_executable("ansible"):
|
||||||
@ -55,6 +58,7 @@ def setup_production(user, bench_path='.', yes=False):
|
|||||||
|
|
||||||
reload_nginx()
|
reload_nginx()
|
||||||
|
|
||||||
|
|
||||||
def disable_production(bench_path='.'):
|
def disable_production(bench_path='.'):
|
||||||
bench_name = get_bench_name(bench_path)
|
bench_name = get_bench_name(bench_path)
|
||||||
|
|
||||||
@ -77,10 +81,11 @@ def disable_production(bench_path='.'):
|
|||||||
|
|
||||||
reload_nginx()
|
reload_nginx()
|
||||||
|
|
||||||
|
|
||||||
def service(service, option):
|
def service(service, option):
|
||||||
if os.path.basename(get_program(['systemctl']) or '') == 'systemctl' and is_running_systemd():
|
if os.path.basename(find_executable('systemctl') or '') == 'systemctl' and is_running_systemd():
|
||||||
exec_cmd("sudo {service_manager} {option} {service}".format(service_manager='systemctl', option=option, service=service))
|
exec_cmd("sudo {service_manager} {option} {service}".format(service_manager='systemctl', option=option, service=service))
|
||||||
elif os.path.basename(get_program(['service']) or '') == 'service':
|
elif os.path.basename(find_executable('service') or '') == 'service':
|
||||||
exec_cmd("sudo {service_manager} {service} {option} ".format(service_manager='service', service=service, option=option))
|
exec_cmd("sudo {service_manager} {service} {option} ".format(service_manager='service', service=service, option=option))
|
||||||
else:
|
else:
|
||||||
# look for 'service_manager' and 'service_manager_command' in environment
|
# look for 'service_manager' and 'service_manager_command' in environment
|
||||||
@ -93,12 +98,14 @@ def service(service, option):
|
|||||||
else:
|
else:
|
||||||
raise Exception('No service manager found')
|
raise Exception('No service manager found')
|
||||||
|
|
||||||
|
|
||||||
def get_supervisor_confdir():
|
def get_supervisor_confdir():
|
||||||
possiblities = ('/etc/supervisor/conf.d', '/etc/supervisor.d/', '/etc/supervisord/conf.d', '/etc/supervisord.d')
|
possiblities = ('/etc/supervisor/conf.d', '/etc/supervisor.d/', '/etc/supervisord/conf.d', '/etc/supervisord.d')
|
||||||
for possiblity in possiblities:
|
for possiblity in possiblities:
|
||||||
if os.path.exists(possiblity):
|
if os.path.exists(possiblity):
|
||||||
return possiblity
|
return possiblity
|
||||||
|
|
||||||
|
|
||||||
def remove_default_nginx_configs():
|
def remove_default_nginx_configs():
|
||||||
default_nginx_configs = ['/etc/nginx/conf.d/default.conf', '/etc/nginx/sites-enabled/default']
|
default_nginx_configs = ['/etc/nginx/conf.d/default.conf', '/etc/nginx/sites-enabled/default']
|
||||||
|
|
||||||
@ -110,6 +117,7 @@ def remove_default_nginx_configs():
|
|||||||
def is_centos7():
|
def is_centos7():
|
||||||
return os.path.exists('/etc/redhat-release') and get_cmd_output("cat /etc/redhat-release | sed 's/Linux\ //g' | cut -d' ' -f3 | cut -d. -f1").strip() == '7'
|
return os.path.exists('/etc/redhat-release') and get_cmd_output("cat /etc/redhat-release | sed 's/Linux\ //g' | cut -d' ' -f3 | cut -d. -f1").strip() == '7'
|
||||||
|
|
||||||
|
|
||||||
def is_running_systemd():
|
def is_running_systemd():
|
||||||
with open('/proc/1/comm') as f:
|
with open('/proc/1/comm') as f:
|
||||||
comm = f.read().strip()
|
comm = f.read().strip()
|
||||||
@ -119,6 +127,7 @@ def is_running_systemd():
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def reload_supervisor():
|
def reload_supervisor():
|
||||||
supervisorctl = find_executable('supervisorctl')
|
supervisorctl = find_executable('supervisorctl')
|
||||||
|
|
||||||
@ -153,7 +162,7 @@ def reload_supervisor():
|
|||||||
|
|
||||||
def reload_nginx():
|
def reload_nginx():
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(['sudo', find_executable('nginx'), '-t'])
|
exec_cmd('sudo {0} -t'.format(find_executable('nginx')))
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user