Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting write permissions on Django Log files

I have a set of Django Log files, for which I have the appropriate logger set to write out messages. However each time it creates a new log file, the permissions on the file don't allow me to start the shell, and at times cause issues with apache.

I have ran chmod -Rv 777 on the directory, which sets all the permissions so we can do what we like, but the next logfile created, goes back to some default.

How can I set permissions on the logfiles to be created

Marc

like image 319
user523013 Avatar asked Sep 08 '13 15:09

user523013


2 Answers

Permissions on files created by a particular user depend on what mask is set for this particular user.

Now you need to set the appropriate permissions for whoever is running the apache service

ps -aux | grep apache | awk '{ print $1 }'

Then for this particular user running apache (www-data?)

sudo chown -R your_user:user_running_apache directory

where directory is the root directory of your django application. To make sure that all the files that will be added to this directory in the future have the correct permissions run:

sudo chmod -R g+s directory
like image 127
matcheek Avatar answered Sep 22 '22 09:09

matcheek


I faced with the same problem - I had issues with starting shell and with celery due to rotated-log file permissions. I'm running my django-project through the uwsgi (which is running by www-data user) - so I handled it by setting umask for it (http://uwsgi-docs.readthedocs.org/en/latest/Options.html#umask).

Also I'm using buildout, so my fix looks like this:

[uwsgi]
recipe = buildout.recipe.uwsgi
xml-socket = /tmp/uwsgi.sock
xml-master = True
xml-chmod-socket = 664
xml-umask = 0002
xml-workers = 3
xml-env = ...
xml-wsgi-file = ...

After this log file permissions became 664, so group members of www-data group can also write into it.

like image 30
Gleb Avatar answered Sep 21 '22 09:09

Gleb