码迷,mamicode.com
首页 > 其他好文 > 详细

Glassfish Payara + jenkins自动部署脚本

时间:2019-06-18 15:48:39      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:clu   clust   语法   dom   file   exit   path   fish   roo   

配置文件内的列需要依次添加
cat AutoDeployConf.conf
#application domain port target contextroot app_name package_path passwordfile
test domain9 4808 test test test /test.war /test_adminpassword.txt

脚本内容,执行方式./auto_deploy_glassfish.sh application
cat auto_deploy_glassfish.sh
#!/bin/bash
. /home/glassfishv4/app_list/glassfishv5_app_list.conf
. /home/glassfishv4/app_list/payara_app_list.conf

rtnCode=0
app_name_param=${1}
curr_host=hostname

echo ${app_name_param}

glassfishv5_asadmin=‘/home/glassfishv4/glassfish5/glassfish/bin/asadmin‘
payara_asadmin=‘/home/glassfishv4/payara41/glassfish/bin/asadmin‘

exec 3<&0 < /home/glassfishv4/AutoDeploy/AutoDeployConf.conf

while read LINE
do
echo "${LINE}" | grep "^#" > /dev/null 2>&1 && continue
[ "${LINE}" = "" ] || [ "${LINE}" = " " ] && continue
application=echo "${LINE}" | awk ‘{print $1}‘
domain_name=echo "${LINE}" | awk ‘{print $2}‘
port=echo "${LINE}" | awk ‘{print $3}‘
target=echo "${LINE}" | awk ‘{print $4}‘
contextroot=echo "${LINE}" | awk ‘{print $5}‘
app_name=echo "${LINE}" | awk ‘{print $6}‘
package_path=echo "${LINE}" | awk ‘{print $7}‘
passwordfile=echo "${LINE}" | awk ‘{print $8}‘

if [ "${application}" != "${app_name_param}" ]; then
continue;
fi

#done
#exec 0<&3 3<&-

if [[ "${glassfishv5_app_list}" =~ ${application} ]]; then

Undeploy

    $glassfishv5_asadmin --passwordfile ${passwordfile} --host ${curr_host} --port ${port} undeploy --target ${target} ${app_name}
    if [ ${?} -ne 0 ]; then
            echo "Undeploy ${application} is failure."
            rtnCode=1
            exit ${rtnCode}
    fi

Shutdown Cluster

    if [ "${target}" == "myplm" ]; then
            $glassfishv5_asadmin --passwordfile ${passwordfile} --host ${curr_host} --port ${port} stop-local-instance --node myplm --nodedir /home/glassfishv4/glassfish5/glassfish/nodes ${target}
            if [ ${?} -ne 0 ]; then
                    echo "Stop myplm instance is failure"
                    rtnCode=1
            fi
    elif [ "${target}" != "server" ]; then
            $glassfishv5_asadmin --passwordfile ${passwordfile} --host ${curr_host} --port ${port} stop-cluster ${target}
            if [ ${?} -ne 0 ]; then
                    echo "Stop ${target} is failure"
                    rtnCode=1
            fi
    fi

Shutdown domain

    $glassfishv5_asadmin stop-domain ${domain_name}
    if [ ${?} -ne 0 ]; then
            echo "Stop ${domain_name} is failure"
            rtnCode=1
    fi

Start domain

    $glassfishv5_asadmin start-domain ${domain_name}
    if [ ${?} -ne 0 ]; then
            echo "Start ${domain_name} is failure"
            rtnCode=1
    fi

Start Cluster

    if [ "${target}" == "myplm" ]; then
            $glassfishv5_asadmin --passwordfile ${passwordfile} --host ${curr_host} --port ${port} start-local-instance --node myplm --nodedir /home/glassfishv4/glassfish5/glassfish/nodes ${target}
            if [ ${?} -ne 0 ]; then
                    echo "Start myplm instance is failure"
                    rtnCode=1
            fi
    elif [ "${target}" != "server" ]; then
            $glassfishv5_asadmin --passwordfile ${passwordfile} --host ${curr_host} --port ${port} start-cluster ${target}
            if [ ${?} -ne 0 ]; then
                    echo "Start ${target} is failure"
                    rtnCode=1
            fi
    fi

Deploy

    $glassfishv5_asadmin --passwordfile ${passwordfile} --host ${curr_host} --port ${port} deploy --name ${app_name} --contextroot ${contextroot} --target ${target} ${package_path}
    if [ ${?} -ne 0 ]; then
            echo "Deploy ${application} is failure"
            rtnCode=1
            exit ${rtnCode}
    fi

elif [[ "${payara_app_list}" =~ ${app_name_param} ]]; then

    $payara_asadmin --passwordfile ${passwordfile} --host ${curr_host} --port ${port} undeploy --target ${target} ${app_name}
    if [ ${?} -ne 0 ]; then
            echo "Undeploy ${application} is failure."
            rtnCode=1
            exit ${rtnCode}
    fi

    if [ "${target}" != "server" ]; then
            $payara_asadmin --passwordfile ${passwordfile} --host ${curr_host} --port ${port} stop-cluster ${target}
            if [ ${?} -ne 0 ]; then
                    echo "Stop ${target} is failure"
                    rtnCode=1
            fi
    fi

    $payara_asadmin stop-domain ${domain_name}
    if [ ${?} -ne 0 ]; then
            echo "Stop ${domain_name} is failure"
            rtnCode=1
    fi

    $payara_asadmin start-domain ${domain_name}
    if [ ${?} -ne 0 ]; then
            echo "Start ${domain_name} is failure"
            rtnCode=1
    fi

    if [ "${target}" != "server" ]; then
            $payara_asadmin --passwordfile ${passwordfile} --host ${curr_host} --port ${port} start-cluster ${target}
            if [ ${?} -ne 0 ]; then
                    echo "Start ${target} is failure"
                    rtnCode=1
            fi
    fi

    $payara_asadmin --passwordfile ${passwordfile} --host ${curr_host} --port ${port} deploy --name ${app_name} --contextroot ${contextroot} --target ${target} ${package_path}
    if [ ${?} -ne 0 ]; then
            echo "Deploy ${application} is failure"
            rtnCode=1
            exit ${rtnCode}
    fi

else
echo "There is no the application."
fi

done
exec 0<&3 3<&-

exit ${rtnCode}

整个过程就是undeploy--stop cluster--stop domain--start domain--start cluster--deploy
具体语法可以在官网直接找到

将脚本信息及war位置配置在jenkins里即可实现自动部署

Glassfish Payara + jenkins自动部署脚本

标签:clu   clust   语法   dom   file   exit   path   fish   roo   

原文地址:https://blog.51cto.com/plking/2410482

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!