salt.modules.tomcat

用于支持Tomcat

This module uses the manager webapp to manage Apache tomcat webapps. If the manager webapp is not configured some of the functions won't work.

configuration:
  • Java bin path should be in default path
  • If ipv6 is enabled make sure you permit manager access to ipv6 interface "0:0:0:0:0:0:0:1"
  • If you are using tomcat.tar.gz it has to be installed or symlinked under /opt, preferably using name tomcat
  • "tomcat.signal start/stop" works but it does not use the startup scripts

The following grains/pillar should be set:

tomcat-manager:
  user: <username>
  passwd: <password>

or the old format:

tomcat-manager.user: <username>
tomcat-manager.passwd: <password>

Also configure a user in the conf/tomcat-users.xml file:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
    <role rolename="manager-script"/>
    <user username="tomcat" password="tomcat" roles="manager-script"/>
</tomcat-users>

注解

salt.modules.tomcat.deploy_war(war, context, force='no', url='http://localhost:8080/manager', saltenv='base', timeout=180, temp_war_location=None, version='')

部署一个WAR文件

war

WAR文件的绝对路径(运行tomcat的账户应该可访问到)或者一个被salt.modules.cp.get_file功能支持的路径

context

部署的context路径

force : False

设置为True将webapp部署在context

url : http://localhost:8080/manager

服务器manager webapp的URL

saltenv : base

WAR文件的环境变量被salt.modules.cp.get_url功能使用

timeout : 180

HTTP请求超时时间

temp_war_location : None

使用另外一个位置临时复制war包文件默认使用系统临时目录

version : ''

Specify the war version. If this argument is provided, it overrides the version encoded in the war file name, if one is present.

Examples:

salt '*' tomcat.deploy_war salt://salt-2015.8.6.war version=2015.08.r6

2015.8.6 新版功能.

CLI范例:

cp module

salt '*' tomcat.deploy_war salt://application.war /api
salt '*' tomcat.deploy_war salt://application.war /api no
salt '*' tomcat.deploy_war salt://application.war /api yes http://localhost:8080/manager

minion本地文件系统

salt '*' tomcat.deploy_war /tmp/application.war /api
salt '*' tomcat.deploy_war /tmp/application.war /api no
salt '*' tomcat.deploy_war /tmp/application.war /api yes http://localhost:8080/manager
salt.modules.tomcat.fullversion()

从catalina.sh version返回所有的服务器信息

CLI 范例:

salt '*' tomcat.fullversion
salt.modules.tomcat.leaks(url='http://localhost:8080/manager', timeout=180)

在tomcat中找出内存泄漏

url : http://localhost:8080/manager

服务器manager webapp的URL

timeout : 180

HTTP请求超时时间

CLI范例:

salt '*' tomcat.leaks
salt.modules.tomcat.ls(url='http://localhost:8080/manager', timeout=180)

列出所有已部署的webapps

url : http://localhost:8080/manager

服务器manager webapp的URL

timeout : 180

HTTP请求超时时间

CLI范例:

salt '*' tomcat.ls
salt '*' tomcat.ls http://localhost:8080/manager
salt.modules.tomcat.passwd(passwd, user='', alg='md5', realm=None)

This function replaces the $CATALINA_HOME/bin/digest.sh script convert a clear-text password to the $CATALINA_BASE/conf/tomcat-users.xml format

CLI范例:

salt '*' tomcat.passwd secret
salt '*' tomcat.passwd secret tomcat sha1
salt '*' tomcat.passwd secret tomcat sha1 'Protected Realm'
salt.modules.tomcat.reload(app, url='http://localhost:8080/manager', timeout=180)

重加载webapp

app

webapp的context路径

url : http://localhost:8080/manager

服务器manager webapp的URL

timeout : 180

HTTP请求超时时间

CLI范例:

salt '*' tomcat.reload /jenkins
salt '*' tomcat.reload /jenkins http://localhost:8080/manager
salt.modules.tomcat.serverinfo(url='http://localhost:8080/manager', timeout=180)

返回服务器的详细信息

url : http://localhost:8080/manager

服务器manager webapp的URL

timeout : 180

HTTP请求超时时间

CLI范例:

salt '*' tomcat.serverinfo
salt '*' tomcat.serverinfo http://localhost:8080/manager
salt.modules.tomcat.sessions(app, url='http://localhost:8080/manager', timeout=180)

返回webapp的sessions信息

app

webapp的context路径

url : http://localhost:8080/manager

服务器manager webapp的URL

timeout : 180

HTTP请求超时时间

CLI范例:

salt '*' tomcat.sessions /jenkins
salt '*' tomcat.sessions /jenkins http://localhost:8080/manager
salt.modules.tomcat.signal(signal=None)

给catalina发送start, stop, securestart, forcestop信号.

CLI 范例:

salt '*' tomcat.signal start
salt.modules.tomcat.start(app, url='http://localhost:8080/manager', timeout=180)

启动webapp

app

webapp的context路径

url : http://localhost:8080/manager

服务器manager webapp的URL

timeout

HTTP请求超时时间

CLI范例:

salt '*' tomcat.start /jenkins
salt '*' tomcat.start /jenkins http://localhost:8080/manager
salt.modules.tomcat.status(url='http://localhost:8080/manager', timeout=180)

如果tomcat manager开启时用来测试

url : http://localhost:8080/manager

服务器manager webapp的URL

timeout : 180

HTTP请求超时时间

CLI范例:

salt '*' tomcat.status
salt '*' tomcat.status http://localhost:8080/manager
salt.modules.tomcat.status_webapp(app, url='http://localhost:8080/manager', timeout=180)

返回webapp的状态(stopped | running | missing)

app

webapp的context路径

url : http://localhost:8080/manager

服务器manager webapp的URL

timeout : 180

HTTP请求超时时间

CLI范例:

salt '*' tomcat.status_webapp /jenkins
salt '*' tomcat.status_webapp /jenkins http://localhost:8080/manager
salt.modules.tomcat.stop(app, url='http://localhost:8080/manager', timeout=180)

停止webapp

app

webapp的context路径

url : http://localhost:8080/manager

服务器manager webapp的URL

timeout : 180

HTTP请求超时时间

CLI范例:

salt '*' tomcat.stop /jenkins
salt '*' tomcat.stop /jenkins http://localhost:8080/manager
salt.modules.tomcat.undeploy(app, url='http://localhost:8080/manager', timeout=180)

取消部署webapp

app

webapp的context路径

url : http://localhost:8080/manager

服务器manager webapp的URL

timeout : 180

HTTP请求超时时间

CLI范例:

salt '*' tomcat.undeploy /jenkins
salt '*' tomcat.undeploy /jenkins http://localhost:8080/manager
salt.modules.tomcat.version()

从catalina.sh version返回服务器版本

CLI 范例:

salt '*' tomcat.version