2
0
mirror of https://github.com/frappe/bench.git synced 2025-02-08 13:48:25 +00:00

[enhancement] ability to call a different service manager to restart nginx using 'service_manager' and 'service_manager_command' config options in config.json

This commit is contained in:
Anand Doshi 2015-08-25 15:12:25 +05:30
parent 5478bb6f26
commit 69ceb7e9b1

View File

@ -1,4 +1,4 @@
from .utils import get_program, exec_cmd, get_cmd_output, fix_prod_setup_perms
from .utils import get_program, exec_cmd, get_cmd_output, fix_prod_setup_perms, get_config
from .config import generate_nginx_config, generate_supervisor_config
from jinja2 import Environment, PackageLoader
import os
@ -6,11 +6,20 @@ import shutil
def restart_service(service):
if os.path.basename(get_program(['systemctl']) or '') == 'systemctl' and is_running_systemd():
exec_cmd("{prog} restart {service}".format(prog='systemctl', service=service))
exec_cmd("{service_manager} restart {service}".format(service_manager='systemctl', service=service))
elif os.path.basename(get_program(['service']) or '') == 'service':
exec_cmd("{prog} {service} restart ".format(prog='service', service=service))
exec_cmd("{service_manager} {service} restart ".format(service_manager='service', service=service))
else:
raise Exception, 'No service manager found'
# look for 'service_manager' and 'service_manager_command' in config.json
config = get_config()
service_manager = config.get("service_manager")
if service_manager:
service_manager_command = (config.get("service_manager_command")
or "{service_manager} restart {service}").format(service_manager=service_manager, service=service)
exec_cmd(service_manager_command)
else:
raise Exception, 'No service manager found'
def get_supervisor_confdir():
possiblities = ('/etc/supervisor/conf.d', '/etc/supervisor.d/', '/etc/supervisord/conf.d', '/etc/supervisord.d')
@ -28,7 +37,7 @@ def remove_default_nginx_configs():
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'
def is_running_systemd():
with open('/proc/1/comm') as f:
comm = f.read().strip()