我正在编写一个Bash脚本,用于自动部署应用到Tomcat服务器。如何从Bash/命令行停止应用程序?
我正在编写一个Bash脚本,用于自动部署应用到Tomcat服务器。如何从Bash/命令行停止应用程序?
另一种方法是使用CURL。在我的情况下,我使用的是没有WGET的公司Windows机器。不过我有CURL,并可以通过GIT BASH终端使用它。
要列出正在Tomcat上运行的应用程序,我运行以下命令(带有user:password)
curl --user admin:admin http://localhost:8080/manager/text/list
然后停止名为 "myapp" 的应用程序
curl --user admin:admin http://localhost:8080/manager/text/stop?path=/myapp
试用这个叫做 tomcat-manager 的命令行脚本来管理Tomcat。它需要Python,但允许你从Unix shell中执行一些操作,例如:
$ tomcat-manager --user=admin --password=newenglandclamchowder \
> http://localhost:8080/manager/ stop /myapp
并且:
$ tomcat-manager --user=admin --password=newenglandclamchowder \
> http://localhost:8080/manager deploy /myapp ~/src/myapp/myapp.war
它通过HTTP与Tomcat通信,因此它在“本地”即通过localhost或从可以访问您的Tomcat实例的任何地方工作。
我知道的最简单的方法是安装Tomcat管理Web应用程序,注意停止应用程序的URL,并使用wget
下载该URL。
我使用 wget
停止和启动应用程序。
tomcat-user.xml
中的用户必须具有 manager-script 角色。
对于 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
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
有三种方法可以停止tomcat应用程序: