PermissionError: [Errno 13] Permission denied: error when creating a second site

Hello Team,

I am trying to set up DNS-based multi-tenancy in ERPNext and Frappe, but on creating the second site, I get the error below. By any chance I can get pointers on why I can’t get passed this step?

erp@server2345:~/frappe-bench$ sudo bench new-site second.site
[sudo] password for erp: 
MySQL root password: 
Restoring Database file...
11.9KiB 0:00:00 [ 327KiB/s] [======================================>] 100%            

Installing frappe...
Updating DocTypes for frappe        : [========================================] 100%
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/erp/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 110, in <module>
    main()
  File "/home/erp/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 20, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/erp/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/erp/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/erp/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/erp/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/erp/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/erp/frappe-bench/env/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/erp/frappe-bench/apps/frappe/frappe/commands/site.py", line 74, in new_site
    _new_site(
  File "/home/erp/frappe-bench/apps/frappe/frappe/installer.py", line 82, in _new_site
    install_app(app, verbose=verbose, set_as_patched=not source_sql)
  File "/home/erp/frappe-bench/apps/frappe/frappe/installer.py", line 196, in install_app
    frappe.get_attr(after_install)()
  File "/home/erp/frappe-bench/apps/frappe/frappe/utils/install.py", line 25, in after_install
    install_basic_docs()
  File "/home/erp/frappe-bench/apps/frappe/frappe/utils/install.py", line 142, in install_basic_docs
    frappe.get_doc(d).insert()
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 263, in insert
    self.run_before_save_methods()
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 1054, in run_before_save_methods
    self.run_method("validate")
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 943, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 1264, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 1246, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/erp/frappe-bench/apps/frappe/frappe/model/document.py", line 940, in fn
    return method_object(*args, **kwargs)
  File "/home/erp/frappe-bench/apps/frappe/frappe/email/doctype/email_domain/email_domain.py", line 25, in validate
    logger = frappe.logger()
  File "/home/erp/frappe-bench/apps/frappe/frappe/__init__.py", line 2042, in logger
    return get_logger(
  File "/home/erp/frappe-bench/apps/frappe/frappe/utils/logger.py", line 63, in get_logger
    handler = RotatingFileHandler(log_filename, maxBytes=max_size, backupCount=file_count)
  File "/usr/lib/python3.8/logging/handlers.py", line 148, in __init__
    BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python3.8/logging/handlers.py", line 55, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python3.8/logging/__init__.py", line 1147, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python3.8/logging/__init__.py", line 1176, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: '/home/erp/frappe-bench/logs/frappe.log'

Seems permission error …

PermissionError: [Errno 13] Permission denied: '/home/erp/frappe-bench/logs/frappe.log'

Use frappe user for run bench commands. sudo should not needed for this kind of commands

Hope this helps.

erp is the frappe user in my case that I have been using all along. I fail to understand the origin of the permission error.

I think the solution is to grant yourself (User) access to the files using the chown or chmod command.


Try this,
chmod -R o+rx /home/erp
and :
sudo nano /etc/supervisor/supervisord.conf

(Add these lines under [unix_http_server])
chmod=0760
chown=erp:erp

you might also need to restart supervisor
sudo -A systemctl restart supervisor

5 Likes

I have tried adjusting supervisor as advised but the error is still persistent. Restarted the server as well after adjusting these parameters.

What baffles me is that I am able to drop sites using the same frappe user, which is erp in my case.

Hey, I just stumbled upon this. You can also consider checking if you set up the correct production user.

$ sudo bench setup production [YOUR-USER]