Skip to content

Commit

Permalink
fix: update supervisord.conf while generating supervisor.conf
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Mar 13, 2020
1 parent d2a70ba commit 1f0a5ce
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions bench/config/supervisor.py
@@ -1,17 +1,26 @@
import os, getpass, click
# imports - standard imports
import configparser
import getpass
import os

# imports - module imports
import bench
from bench.app import get_current_frappe_version, use_rq
from bench.utils import get_bench_name, find_executable
from bench.config.common_site_config import get_config, update_config, get_gunicorn_workers

def generate_supervisor_config(bench_path, user=None, yes=False):
from bench.app import get_current_frappe_version, use_rq
from bench.utils import get_bench_name, find_executable
from bench.config.common_site_config import get_config, update_config, get_gunicorn_workers
# imports - third party imports
import click

template = bench.env.get_template('supervisor.conf')

def generate_supervisor_config(bench_path, user=None, yes=False):
if not user:
user = getpass.getuser()

config = get_config(bench_path=bench_path)
update_supervisord_conf(user=user)

template = bench.env.get_template('supervisor.conf')
config = get_config(bench_path=bench_path)
bench_dir = os.path.abspath(bench_path)

config = template.render(**{
Expand Down Expand Up @@ -44,3 +53,24 @@ def generate_supervisor_config(bench_path, user=None, yes=False):
update_config({'restart_supervisor_on_update': True}, bench_path=bench_path)
update_config({'restart_systemd_on_update': False}, bench_path=bench_path)


def get_supervisord_conf():
possibilities = ("supervisord.conf", "etc/supervisord.conf", "/etc/supervisord.conf", "/etc/supervisor/supervisord.conf", "/etc/supervisord.conf")

for possibility in possibilities:
if os.path.exists(possibility):
return possibility


def update_supervisord_conf(user):
"""From bench v5.0, we're moving to supervisor running as user"""
supervisord_conf = get_supervisord_conf() or "supervisord.conf"
section = "unix_http_server"

config = configparser.ConfigParser()
config.read(supervisord_conf)
config[section]["chmod"] = "0760"
config[section]["chown"] = user

with open(supervisord_conf, "w") as f:
config.write(f)

0 comments on commit 1f0a5ce

Please sign in to comment.