ber*_*ami 6 deployment jboss curl wildfly
我们想用curl替换app.war的现有部署.下面的帖子提供了部署war文件的好方法.只要没有使用相同名称部署的war文件,这种方法就可以正常工作.但是,如果已经存在部署,则失败.有什么办法可以通过curl替换现有的部署吗?
http://blog.arungupta.me/2014/01/deploy-to-wildfly-using-curl-tech-tip-10/
有没有办法获得wildfly的HTTP API的完整界面文档
nio*_*ioe 12
我们写了一个小的Shell脚本来实现这个目的:
#!/bin/bash
echo "Undeploy old war"
curl -S -H "content-Type: application/json" -d '{"operation":"undeploy", "address":[{"deployment":"old.war"}]}' --digest http://user:password@hostname:9990/management
echo ""
echo "Remove old war"
curl -S -H "content-Type: application/json" -d '{"operation":"remove", "address":[{"deployment":"old.war"}]}' --digest http://user:password@hostname:9990/management
echo ""
echo "Upload new war"
bytes_value=`curl -F "file=@/path/to/new.war" --digest http://user:password@$hostname:9990/management/add-content | perl -pe 's/^.*"BYTES_VALUE"\s*:\s*"(.*)".*$/$1/'`
echo $bytes_value
json_string_start='{"content":[{"hash": {"BYTES_VALUE" : "'
json_string_end='"}}], "address": [{"deployment":"new.war"}], "operation":"add", "enabled":"true"}'
json_string="$json_string_start$bytes_value$json_string_end"
echo "Deploy new war"
result=`curl -S -H "Content-Type: application/json" -d "$json_string" --digest http://user:password@hostname:9990/management | perl -pe 's/^.*"outcome"\s*:\s*"(.*)".*$/$1/'`
echo $result
if [ "$result" != "success" ]; then
exit -1
fi
Run Code Online (Sandbox Code Playgroud)
首先,旧的WAR-File将被删除.之后,新的存档被上传和部署.对我们来说,即使尚未部署任何内容,这仍然有效.在这种情况下,前两个调用将失败,但无论如何都将部署新内容.
通过从Wildfly Maven-Plugin切换到此脚本,我们能够将部署时间从大约20分钟缩短到4分钟!
希望有所帮助.干杯
非常感谢@nioe 的脚本!这是一个可配置的版本,静音curl更适合 CI 脚本:
#!/bin/bash
# Deploys given WAR to WildFly server, pass full path to WAR as argument
set -e
set -u
[[ -f "$1" ]] || { >&2 echo "Usage: $0 WAR-filename ('$1' is not a file)"; exit 1; }
WILDFLY_MANAGEMENT_URL=http://username:password@hostname:9990
WAR_NAME=`basename $1`
WAR_PATH=`dirname $1`
echo "Deploying '$WAR_NAME' from '$WAR_PATH' to '$WILDFLY_MANAGEMENT_URL'"
echo '-------------------'
echo "-> Undeploy old war"
curl -sS -H "content-Type: application/json" -d '{"operation":"undeploy", "address":[{"deployment":"'"${WAR_NAME}"'"}]}' --digest ${WILDFLY_MANAGEMENT_URL}/management
echo ""
echo "-> Remove old war"
curl -sS -H "content-Type: application/json" -d '{"operation":"remove", "address":[{"deployment":"'"${WAR_NAME}"'"}]}' --digest ${WILDFLY_MANAGEMENT_URL}/management
echo ""
echo "-> Upload new war"
bytes_value=`curl -sF "file=@${WAR_PATH}/${WAR_NAME}" --digest ${WILDFLY_MANAGEMENT_URL}/management/add-content | perl -pe 's/^.*"BYTES_VALUE"\s*:\s*"(.*)".*$/$1/'`
echo $bytes_value
json_string_start='{"content":[{"hash": {"BYTES_VALUE" : "'
json_string_end='"}}], "address": [{"deployment":"'"${WAR_NAME}"'"}], "operation":"add", "enabled":"true"}'
json_string="$json_string_start$bytes_value$json_string_end"
echo "-> Deploy new war"
result=`curl -sS -H "Content-Type: application/json" -d "$json_string" --digest ${WILDFLY_MANAGEMENT_URL}/management | perl -pe 's/^.*"outcome"\s*:\s*"(.*)".*$/$1/'`
echo $result
if [ "$result" != "success" ]; then
exit -1
fi
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3877 次 |
| 最近记录: |