diff --git a/bench/cli.py b/bench/cli.py index 097d8028..42b6636b 100644 --- a/bench/cli.py +++ b/bench/cli.py @@ -23,6 +23,7 @@ import sys import logging import copy import pwd +import grp logger = logging.getLogger('bench') @@ -385,7 +386,35 @@ def _patch_mariadb_config(): repo_dir = os.path.dirname(__file__) exec_cmd(os.path.join(repo_dir, 'patches', 'fix-mariadb.sh'), cwd=os.path.join(repo_dir, 'patches')) +@click.command('fix-perms') +def _fix_perms(): + "Fix permissions if supervisor processes were run as root" + files = [ + "logs/web.error.log", + "logs/web.log", + "logs/workerbeat.error.log", + "logs/workerbeat.log", + "logs/worker.error.log", + "logs/worker.log", + "config/nginx.conf", + "logs/supervisor.conf", + ] + + frappe_user = get_config().get('frappe_user') + if not frappe_user: + print "frappe user not set" + sys.exit(1) + + for path in files: + if os.path.exists(path): + uid = pwd.getpwnam(frappe_user).pw_uid + gid = grp.getgrnam(frappe_user).gr_gid + os.chown(path, uid, gid) + + exec_cmd("{bench} setup supervisor".format(bench=sys.argv[0])) + patch.add_command(_patch_mariadb_config) +patch.add_command(_fix_perms) #Bench commands