简体   繁体   English

Apache Tomcat记录默认权限

[英]Apache Tomcat logging default permissions

I'm wondering if there's any way to set default file permissions of the logs created using Tomcat's logging.properties files? 我想知道是否有办法设置使用Tomcat的logging.properties文件创建的日志的默认文件权限? My logging.properties file looks like this: 我的logging.properties文件如下所示:

handlers = java.util.Logging.FileHandler

java.util.logging.FileHandler.level = INFO
java.util.logging.FileHandler.pattern = /var/lib/<TOMCAT INSTANCE>/logs/system.log
java.util.logging.FileHandler.limit = 2097152
java.util.logging.FileHandler.count = 50
java.util.logging.FileHandler.formatter = java.util.Logging.SimpleFormatter

I want all logs that are created to have file permissions of 640, however after reading some documentation about FileHandler and other alternatives, I'm not sure this is possible. 我希望创建的所有日志都具有640的文件权限,但是在阅读了一些关于FileHandler和其他替代方案的文档后,我不确定这是否可行。

Any help/direction would be greatly appreciated! 任何帮助/方向将不胜感激!

Thanks for your time. 谢谢你的时间。

I spent a long time searching for this today, so I'm posting my solution to this old ticket. 我今天花了很长时间搜索这个,所以我发布了我的解决方案。 I am working from a Linux install, which I believe is what the original poster was also using. 我在Linux安装工作,我相信原始海报也在使用。

In Tomcat 8.5, this is controlled with the environment variable UMASK. 在Tomcat 8.5中,它由环境变量UMASK控制。 If this variable is not set when Tomcat is started, then Tomcat will set the umask to 0027, so that files have the permissions (rw-r-----). 如果在启动Tomcat时未设置此变量,则Tomcat会将umask设置为0027,以便文件具有权限(rw-r -----)。 You can see this logic for this in Tomcat's bin/catalina.sh file. 您可以在Tomcat的bin / catalina.sh文件中看到此逻辑。

This solution is different from pksiazek's solution because it does not involve editing any of Tomcat's scripts, in case that is a concern. 这个解决方案与pksiazek的解决方案不同,因为它不涉及编辑任何Tomcat的脚本,如果这是一个问题。 It is the same as pksiazek's solution in that it will affect all files created by Tomcat, not just log files. 它与pksiazek的解决方案相同,它将影响Tomcat创建的所有文件,而不仅仅是日志文件。

For anyone not as familiar with how umask values map to file permissions, you may find a Umask calculator helpful. 对于不熟悉umask值如何映射到文件权限的人,您可能会发现Umask计算器很有用。 Here's one: http://www.webune.com/forums/umask-calculator.html 这是一个: http//www.webune.com/forums/umask-calculator.html

The only way is to change umask for owner of Tomcat process (best place from that would be Tomcat startup script). 唯一的方法是为Tomcat进程的所有者更改umask(最好的地方就是Tomcat启动脚本)。

But beware that this will change permissions of ALL files created by Tomcat. 但请注意,这将更改Tomcat创建的所有文件的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM