Ubuntu / Django / Logging / PermissionError: [Errno 13] В доступе отказано - PullRequest
0 голосов
/ 26 марта 2019

Ubuntu 18.04.1 использование стека Битнами Джанго: битнами-джангостак-2.1.5-1

Я получаю эту ошибку при запуске службы Apache:

[16:21:20.028270 2019] [wsgi:error]  Traceback (most recent call last):
[16:21:20.028373 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/config.py", line 562, in configure
[16:21:20.028395 2019] [wsgi:error]      handler = self.configure_handler(handlers[name])
[16:21:20.028421 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/config.py", line 735, in configure_handler
[16:21:20.028438 2019] [wsgi:error]      result = factory(**kwargs)
[16:21:20.028463 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/handlers.py", line 147, in __init__
[16:21:20.028479 2019] [wsgi:error]      BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
[16:21:20.028504 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/handlers.py", line 54, in __init__
[16:21:20.028520 2019] [wsgi:error]      logging.FileHandler.__init__(self, filename, mode, encoding, delay)
[16:21:20.028545 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/__init__.py", line 1092, in __init__
[16:21:20.028562 2019] [wsgi:error]      StreamHandler.__init__(self, self._open())
[16:21:20.028601 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/__init__.py", line 1121, in _open
[16:21:20.028618 2019] [wsgi:error]      return open(self.baseFilename, self.mode, encoding=self.encoding)
[16:21:20.028666 2019] [wsgi:error]  PermissionError: [Errno 13] Permission denied: '/opt/djangostack-2.1.5-1/apps/django/django_projects/myproject/static/logs/ca.myproject.app.cleaner.log'
[16:21:20.028701 2019] [wsgi:error]  
[16:21:20.028716 2019] [wsgi:error]  The above exception was the direct cause of the following exception:
[16:21:20.028729 2019] [wsgi:error]  
[16:21:20.028753 2019] [wsgi:error]  Traceback (most recent call last):
[16:21:20.028832 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/apps/django/django_projects/myproject/myproject/wsgi.py", line 19, in <module>
[16:21:20.028851 2019] [wsgi:error]      application = get_wsgi_application()
[16:21:20.028886 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/apps/django/lib/python3.7/site-packages/Django-2.1.5-py3.7.egg/django/core/wsgi.py", line 12, in get_wsgi_application
[16:21:20.028903 2019] [wsgi:error]      django.setup(set_prefix=False)
[16:21:20.028928 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/apps/django/lib/python3.7/site-packages/Django-2.1.5-py3.7.egg/django/__init__.py", line 19, in setup
[16:21:20.028944 2019] [wsgi:error]      configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[16:21:20.028968 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/apps/django/lib/python3.7/site-packages/Django-2.1.5-py3.7.egg/django/utils/log.py", line 76, in configure_logging
[16:21:20.028984 2019] [wsgi:error]      logging_config_func(logging_settings)
[16:21:20.029008 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/config.py", line 799, in dictConfig
[16:21:20.029023 2019] [wsgi:error]      dictConfigClass(config).configure()
[16:21:20.029046 2019] [wsgi:error]    File "/opt/djangostack-2.1.5-1/python/lib/python3.7/logging/config.py", line 570, in configure
[16:21:20.029062 2019] [wsgi:error]      '%r' % name) from e
[16:21:20.029102 2019] [wsgi:error]  ValueError: Unable to configure handler 'cleaner_file'

Как это исправить?

Django не может создать файл журнала в каталоге /opt/djangostack-2.1.5-1/apps/django/django_projects/myproject/static/logs/

В моем проекте settings.py путь к файлу указан как абсолютный путь, поэтому Django должен иметь возможность записать файл журнала в папку.

Краткое исправление: chmod -R 777 $(pwd)/static/logs это решит проблему, но после перезагрузки ошибка вернется: (

Спасибо за любую помощь

Как только журнал достигнет максимального размера, будет создан новый файл с правами root, см. Ниже:


-rw-rw-r--  1 daemon daemon        0 Jun  5 13:54 my_project.debug.log
-rw-rw-r--  1 daemon daemon    15319 Jun 12 17:52 my_project.app.log
**-rw-r--r--  1 root   root     159042 Jun 12 17:52 my_project.ws.log** --> HERE
-rw-rw-r--  1 daemon daemon 15700891 Jun 12 17:52 my_project.ws.log.1
-rw-rw-r--  1 daemon daemon 15711651 Jun 12 16:53 my_project.ws.log.2

...