是什么决定了Tomcat Java进程的当前工作目录? [英] What determines the current working directory of Tomcat Java process?

查看:106
本文介绍了是什么决定了Tomcat Java进程的当前工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的生产服务器使用System V样式的init脚本运行Linux。



运行服务tomcat6 start 以root用户身份( service 在cwd / 下运行init脚本)。



然后Tomcat提供一个网页来写出 new File(。)。getAbsolutePath()的结果,显示 / usr / share / tomcat6 /.



但Tomcat init脚本( /etc/init.d/tomcat6 )没有提及CWD,也没有任何 cd 命令。



给定Java本身无法更改当前的工作目录,那么 / usr / share / tomcat6 如何成为Tomcat的当前工作目录?它的启动过程在哪里改变它的cwd?



有问题的Linux是CentOS6。

解决方案

在CentOS 6上,Tomcat init.d脚本通过以下行启动tomcat:

  $ SU -  $ TOMCAT_USER -c$ {TOMCAT_SCRIPT} start-security

$ SU是/ bin / runuser或/ bin / su,$ TOMCAT_USER通常是tomcat,而$ TOMCAT_SCRIPT通常是/ usr / sbin / tomcat6。 su - 或runuser - 从指定用户的主目录以指定用户身份运行其命令。因此,此命令将更改为tomcat用户的ID和主目录,然后运行/ usr / sbin / tomcat6。 tomcat6脚本最终会自动启动tomcat。



tomcat用户的主目录应该与CATALINA_BASE相同。简而言之,这里的su或runuser命令将当前工作目录设置为CATALINA_BASE。



init.d脚本不是tomcat的正式部分;它由软件包维护者提供,它可以因系统而异。在我的Ubuntu 13系统上, /etc/init.d/tomcat6 包含一个命令 cd 到$ CATALINA_BASE。 / p>

Tomcat自己的启动脚本(bin / startup.sh等)不设置工作目录。当我使用自己的启动脚本直接启动tomcat 6或tomcat 7时,它只是继承了我运行它的工作目录。



请记住,在Linux上,你可以看到通过检查 / proc /< pid> / cwd 来检查任何进程的实际当前目录。


My production server runs Linux using System V style init scripts.

Tomcat is brought up by running service tomcat6 start as root user (service runs init script under cwd /).

Tomcat then serves a web page to write the result of new File(".").getAbsolutePath(), which shows /usr/share/tomcat6/.

But Tomcat init script (/etc/init.d/tomcat6) makes no mention of CWD, neither does it have any cd command.

Given that Java itself cannot change current working directory, then how come /usr/share/tomcat6 became Tomcat's current working directory? Where in its startup process changes its cwd?

The Linux in question is CentOS6.

解决方案

On CentOS 6, the Tomcat init.d script launches tomcat by means of this line:

$SU - $TOMCAT_USER -c "${TOMCAT_SCRIPT} start-security"

$SU is either /bin/runuser or /bin/su, $TOMCAT_USER is normally "tomcat", and $TOMCAT_SCRIPT is normally "/usr/sbin/tomcat6". "su -" or "runuser -" runs its command as the specified user, from the specified user's home directory. So this command will change to the "tomcat" user's ID and home directory, then run /usr/sbin/tomcat6. The tomcat6 script eventually launches tomcat itself.

The tomcat user's home directory should be the same as CATALINA_BASE. In short, the "su" or "runuser" command here is what sets the current working directory to CATALINA_BASE.

The init.d script isn't formally part of tomcat; it's supplied by the package maintainer, and it can be different from one system to another. On my Ubuntu 13 system, /etc/init.d/tomcat6 contains a command to cd to $CATALINA_BASE.

Tomcat's own startup scripts (bin/startup.sh and so on) don't set a working directory. When I launch tomcat 6 or tomcat 7 directly using its own startup script, it just inherits the working directory that I ran it from.

Remember that on Linux, you can see any process's actual current directory by checking /proc/<pid>/cwd.

这篇关于是什么决定了Tomcat Java进程的当前工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆