Skip to content

Commit

Permalink
fix: run fix_user_permissions only if production or sudoers is set up
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Mar 16, 2020
1 parent 849c751 commit fe02844
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
3 changes: 0 additions & 3 deletions bench/config/supervisor.py
Expand Up @@ -69,9 +69,6 @@ def update_supervisord_conf(user):
supervisord_conf = get_supervisord_conf()
section = "unix_http_server"

if not supervisord_conf:
return

config = configparser.ConfigParser()
config.read(supervisord_conf)
config[section]["chmod"] = "0760"
Expand Down
33 changes: 25 additions & 8 deletions bench/patches/v5/fix_user_permissions.py
@@ -1,21 +1,38 @@
# imports - standard imports
import os
import subprocess
import sys

# imports - module imports
from bench.utils import get_cmd_output, exec_cmd, which
from bench.cli import change_uid_msg
from bench.config.production_setup import get_supervisor_confdir, is_centos7
from bench.utils import exec_cmd, get_bench_name, get_cmd_output


def execute(bench_path):
def is_sudoers_set():
cmd = ["sudo", "-n", "bench"]
return (not subprocess.call(cmd)) or (change_uid_msg in get_cmd_output(cmd))


def is_production_set(bench_path):
production_setup = False
bench_name = get_bench_name(bench_path)

supervisor_conf_extn = "ini" if is_centos7() else "conf"
supervisor_conf_file_name = '{bench_name}.{extn}'.format(bench_name=bench_name, extn=supervisor_conf_extn)
supervisor_conf = os.path.join(get_supervisor_confdir(), supervisor_conf_file_name)

is_bench_sudoers_set = (not subprocess.call(cmd)) or (change_uid_msg in get_cmd_output(cmd))
is_supervisor_installed = which('supervisorctl')
if os.path.exists(supervisor_conf):
production_setup = production_setup or True

if not is_supervisor_installed:
exec_cmd("{} -m pip install supervisor".format(sys.executable))
nginx_conf = '/etc/nginx/conf.d/{bench_name}.conf'.format(bench_name=bench_name)

if is_bench_sudoers_set:
if os.path.exists(nginx_conf):
production_setup = production_setup or True

return production_setup


def execute(bench_path):
if is_sudoers_set() or is_production_set(bench_path):
exec_cmd("sudo bench setup supervisor --yes")
exec_cmd("sudo bench setup sudoers")

0 comments on commit fe02844

Please sign in to comment.