-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Wsgi : error PermissionError : Permission denied" while trying to write to a log file #737
Comments
See:
https://modwsgi.readthedocs.io/en/master/user-guides/application-issues.html#application-working-directory <https://modwsgi.readthedocs.io/en/master/user-guides/application-issues.html#application-working-directory>
The issue is that you are using a relative path name rather than an absolute path name for the log file. As a consequence it is going to be written to the current working directory of the process, which will be root directory of the file system, which only root can write to. You need to calculate an absolute path name for the file to the derived location you want to write it.
Graham
… On 27 Nov 2021, at 12:39 am, Tony-dot-Frank ***@***.***> wrote:
I have a flask application running on a ubuntu server
I have tried to play around with other possible permission settings. I have tried setting the user 'www-data' as the owner of the folder using chown. Ive tried setting the ownerhsip of www-data using groups. Nothing seems to work.
-rw-rw-r-- 1 www-data www-data 3286 Nov 25 10:09 imm_migration.log
This is my Full error message
[Fri Nov 26 11:05:22.302892 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] mod_wsgi (pid=1453): Failed to exec Python script file '/home/admin/imm-migration/easyucs_api.wsgi'.
[Fri Nov 26 11:05:22.302940 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] mod_wsgi (pid=1453): Exception occurred processing WSGI script '/home/admin/imm-migration/easyucs_api.wsgi'.
[Fri Nov 26 11:05:22.303054 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] Traceback (most recent call last):
[Fri Nov 26 11:05:22.303093 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.wsgi", line 8, in <module>
[Fri Nov 26 11:05:22.303099 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] main()
[Fri Nov 26 11:05:22.303105 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.py", line 225, in main
[Fri Nov 26 11:05:22.303119 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] easyucs = Easyucs(logger_handle_log_level="debug", log_file_path="imm_migration.log")
[Fri Nov 26 11:05:22.303127 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.py", line 38, in __init__
[Fri Nov 26 11:05:22.303144 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] self._init_logger()
[Fri Nov 26 11:05:22.303149 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/home/admin/imm-migration/easyucs_api.py", line 102, in _init_logger
[Fri Nov 26 11:05:22.303154 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] fh = logging.FileHandler(self._log_file_path)
[Fri Nov 26 11:05:22.303159 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/usr/lib/python3.8/logging/__init__.py", line 1143, in __init__
[Fri Nov 26 11:05:22.303162 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] StreamHandler.__init__(self, self._open())
[Fri Nov 26 11:05:22.303167 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] File "/usr/lib/python3.8/logging/__init__.py", line 1172, in _open
[Fri Nov 26 11:05:22.303171 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] return open(self.baseFilename, self.mode, encoding=self.encoding)
[Fri Nov 26 11:05:22.303186 2021] [wsgi:error] [pid 1453:tid 140081484965632] [remote 10.81.0.121:57056] PermissionError: [Errno 13] Permission denied: '/imm_migration.log'
i have set the user and the owner to www-data to the whole working directory
This is my apache conf
<VirtualHost *:80>
ServerAdmin ***@***.***
DocumentRoot /home/admin/imm-migration
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/admin/imm-migration>
# set permissions as per apache2.conf file
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
WSGIDaemonProcess migration python-path=/home/admin/imm-migration
LoadModule wsgi_module "/usr/local/lib/python3.8/dist-packages/mod_wsgi/server/mod_wsgi-py38.cpython-38-x86_64-linux-gnu.so"
WSGIScriptAlias / /home/admin/imm-migration/easyucs_api.wsgi
WSGIApplicationGroup %{GLOBAL}
WSGIProcessGroup migration
WSGIPassAuthorization On
</VirtualHost>
python version 3.8
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#737>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAD355KS36NFNCMR5URWHDTUN6EZTANCNFSM5I2WCDNQ>.
Triage notifications on the go with GitHub Mobile for iOS <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Hi Graham, Thanks for the reply I have tried providing absolute path for the log file too. Still facing the error
Full error message
|
What do you get for:
|
ls -lasd /home/admin/imm-migration |
If the log still shows:
then you can't be setting the path in the correct location as it still shows Ensure you do a full stop/start of Apache to ensure your modified code is being picked up. BTW, your configuration has:
inside of the |
But earlier i managed to bring up the UI of the application..Is there any way to check if the config is being used |
What is the full path name to that Apache config file? If it is in a As to checking if in use, add something which is an obvious error in the file, such as:
Apache should fail to start if that file is being read. |
The apache failed to start once i added something wrong in configration...seems the config is being used
So i rebooted the machine and the permission error no longer exist. For some reason my modified code is didnt picked up |
I added something which is error im my configration and the apache threw error. Seems like the config is even used. |
Okay, that's odd, never noticed that before. https://httpd.apache.org/docs/2.4/mod/mod_so.html#loadmodule This says that LoadModule can be used inside of a VirtualHost definition. Not sure why they would want to allow that since it isn't going to be isolated to the VirtualHost. Anyway, it is more conventional to have it outside of VirtualHost and on debian/ubuntu is usually loaded from a file in a mods-available directory. Anyway, sounds like the path issue is fixed at least. |
Yes Graham the path issue is fixed..appreciate your help so much.Thank you |
PermissionError Traceback (most recent call last) You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection |
I have a flask application running on a ubuntu server
I have tried to play around with other possible permission settings. I have tried setting the user 'www-data' as the owner of the folder using chown. Ive tried setting the ownerhsip of www-data using groups. Nothing seems to work.
-rw-rw-r-- 1 www-data www-data 3286 Nov 25 10:09 imm_migration.log
This is my Full error message
i have set the user and the owner to www-data to the whole working directory
This is my apache conf
python version 3.8
The text was updated successfully, but these errors were encountered: