从命令行停止web应用程序tomcat
我正在编写一个bash脚本,自动将应用程序部署到tomcat服务器。如何从bash/命令行停止应用程序?我所知道的最简单的方法是安装Tomcat manager webapp,注意停止应用程序的URL,以及该URL。停止Tomcat应用程序有三种方法从命令行停止web应用程序tomcat,tomcat,web-applications,deployment,web-deployment,Tomcat,Web Applications,Deployment,Web Deployment,我正在编写一个bash脚本,自动将应用程序部署到tomcat服务器。如何从bash/命令行停止应用程序?我所知道的最简单的方法是安装Tomcat manager webapp,注意停止应用程序的URL,以及该URL。停止Tomcat应用程序有三种方法 通过本地访问,您当然可以停止该过程。这完全阻止了tomcat 通过本地和远程访问,您可以使用密码访问server.xml(默认值=8005)中定义的“关机端口”。如果您打开一个套接字并发送密码,tomcat将完全关闭 你听从山姆的建议,这让你有选择
$ tomcat-manager --user=admin --password=newenglandclamchowder \
> http://localhost:8080/manager/ stop /myapp
以及:
因为它通过HTTP与tomcat通信,所以它在“本地”工作,即通过本地主机,或者从任何可以访问tomcat实例的地方工作。我使用
wget
停止和启动应用程序。
tomcat user.xml
中的用户必须具有管理器脚本角色
对于TOMCAT 5/6:
wget "http://<user>:<password>@<servername>:<port>/manager/stop?=/<application context>" -O - -q
wget "http://<user>:<password>@<servername>:<port>/manager/start?=/<application context>" -O - -q
另一种方法是使用CURL。在我的情况下,我在一台没有WGET的公司Windows机器上。不过我有CURL,可以通过gitbash终端使用它 为了列出在Tomcat上运行的应用程序,我运行以下命令(使用user:password) 然后停止名为“myapp”的应用程序
你想在本地还是远程阻止Tomcat?我只是想在本地阻止它。完全击败Tomcat不是我的目标。我确实希望有选择性,因为我不想停止任何其他并行运行的应用程序。那么sam的建议是正确的。请注意,在取消部署/重新部署的情况下,应用程序服务器很容易泄漏内存……这是正确的答案:如果要停止单个Web应用程序,则必须使用Tomcat的内部API或使用JMX。Manager webapp是为您想做的一切而设置的,而且为Manager webapp配置安全性也很容易。我的停止URL应该包含“org.apache.catalina.filters.CSRF_NONCE”标记。它使这种方法复杂化。Kotfu的回答更详细地说明了这一点。如果您有一个带有hashtag符号(#)的并行部署,请记住您必须将其URL编码到路径中的%23。
wget "http://<user>:<password>@<servername>:<port>/manager/stop?=/<application context>" -O - -q
wget "http://<user>:<password>@<servername>:<port>/manager/start?=/<application context>" -O - -q
wget "http://<user>:<password>@<servername>:<port>/manager/text/stop?path=/<application context>" -O - -q
wget "http://<user>:<password>@<servername>:<port>/manager/text/start?path=/<application context>" -O - -q
curl --user admin:admin http://localhost:8080/manager/text/list
curl --user admin:admin http://localhost:8080/manager/text/stop?path=/myapp