设置Django日志文件的写权限

时间:2021-12-31 16:45:55

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.

我有一组Django日志文件,为此我有适当的记录器设置来写出消息。但是每次创建新的日志文件时,文件的权限都不允许我启动shell,有时会导致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.

我在目录上运行了chmod -Rv 777,它设置了所有权限,因此我们可以做我们喜欢的事情,但是创建的下一个日志文件会回到默认状态。

How can I set permissions on the logfiles to be created

如何设置要创建的日志文件的权限

Marc

渣子

2 个解决方案

#1


3  

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

现在,您需要为运行apache服务的任何人设置适当的权限

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

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

然后为这个运行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:

其中directory是django应用程序的根目录。要确保将来添加到此目录的所有文件都具有正确的权限:

sudo chmod -R g+s directory

#2


1  

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).

我遇到了同样的问题 - 由于旋转日志文件权限,我遇到了启动shell和芹菜的问题。我通过uwsgi(由www-data用户运行)运行我的django项目 - 所以我通过为它设置umask来处理它(http://uwsgi-docs.readthedocs.org/en/latest/Options。 HTML#的umask)。

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

我也在使用buildout,所以我的修复看起来像这样:

[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.

在此日志文件权限变为664之后,www-data组的组成员也可以写入其中。

#1


3  

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

现在,您需要为运行apache服务的任何人设置适当的权限

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

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

然后为这个运行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:

其中directory是django应用程序的根目录。要确保将来添加到此目录的所有文件都具有正确的权限:

sudo chmod -R g+s directory

#2


1  

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).

我遇到了同样的问题 - 由于旋转日志文件权限,我遇到了启动shell和芹菜的问题。我通过uwsgi(由www-data用户运行)运行我的django项目 - 所以我通过为它设置umask来处理它(http://uwsgi-docs.readthedocs.org/en/latest/Options。 HTML#的umask)。

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

我也在使用buildout,所以我的修复看起来像这样:

[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.

在此日志文件权限变为664之后,www-data组的组成员也可以写入其中。