2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-11 15:51:03 +00:00

add fix-file-perms

This commit is contained in:
Pratik Vyas 2015-01-29 19:20:49 +05:30
parent 5fc81d0a3e
commit ac9b2bcf63
2 changed files with 21 additions and 6 deletions

View File

@ -13,7 +13,7 @@ from .utils import set_default_site as _set_default_site
from .utils import (build_assets, patch_sites, exec_cmd, update_bench, get_frappe, setup_logging,
get_config, update_config, restart_supervisor_processes, put_config, default_config, update_requirements,
backup_all_sites, backup_site, get_sites, prime_wheel_cache, is_root, set_mariadb_host, drop_privileges,
fix_file_perms, set_ssl_certificate, set_ssl_certificate_key)
fix_file_perms, fix_prod_setup_perms, set_ssl_certificate, set_ssl_certificate_key)
from .app import get_app as _get_app
from .app import new_app as _new_app
from .app import pull_all_apps
@ -59,6 +59,8 @@ def change_uid():
sys.exit(1)
def change_dir():
if os.path.exists('config.json'):
return
dir_path_file = '/etc/frappe_bench_dir'
if os.path.exists(dir_path_file):
with open(dir_path_file) as f:
@ -410,20 +412,26 @@ config.add_command(config_http_timeout)
def patch():
pass
@click.command('fix-perms')
def _fix_perms():
@click.command('fix-prod-perms')
def _fix_prod_perms():
"Fix permissions if supervisor processes were run as root"
if os.path.exists("config/supervisor.conf"):
exec_cmd("supervisorctl stop frappe:")
fix_file_perms()
fix_prod_setup_perms()
if os.path.exists("config/supervisor.conf"):
exec_cmd("{bench} setup supervisor".format(bench=sys.argv[0]))
exec_cmd("supervisorctl reload")
patch.add_command(_fix_perms)
@click.command('fix-file-perms')
def _fix_file_perms():
"Fix file permissions"
fix_file_perms()
patch.add_command(_fix_file_perms)
patch.add_command(_fix_prod_perms)
#Bench commands

View File

@ -330,7 +330,7 @@ def drop_privileges(uid_name='nobody', gid_name='nogroup'):
# Ensure a very conservative umask
old_umask = os.umask(022)
def fix_file_perms(frappe_user=None):
def fix_prod_setup_perms(frappe_user=None):
files = [
"logs/web.error.log",
"logs/web.log",
@ -354,3 +354,10 @@ def fix_file_perms(frappe_user=None):
uid = pwd.getpwnam(frappe_user).pw_uid
gid = grp.getgrnam(frappe_user).gr_gid
os.chown(path, uid, gid)
def fix_file_perms():
for dir_path, dirs, files in os.walk('.'):
for _dir in dirs:
os.chmod(os.path.join(dir_path, _dir), 0755)
for _file in files:
os.chmod(os.path.join(dir_path, _file), 0644)