java自动部署/启动脚本(linux)

1.jar

#!/bin/bash
#
pkg_path=/tmp
run_path=/usr
version=1.0.0
uptime=`date +"%F"`

cd $run_path

pkgs=(jar1 jar2 jar3)
for pkg in ${pkgs[@]}
do

mv $pkg-$version.jar $pkg_path/bak/$pkg-$version.jar.$uptime
cp $root_path/packages/$pkg-$version.jar $pkg-$version.jar

PID=`ps -ef|grep $pkg-$version|egrep -v grep|awk '{print $2}'`
if [ ! "$PID" = "" ]
then
kill $PID
echo "KILL $PID:"
fi

sleep 2
nohup java -Xmx128m -Xms128m -jar $pkg-$version.jar >$pkg.$uptime.out 2>&1 &

PID2=`ps -ef|grep $pkg|egrep -v grep|awk '{print $2}'`
[ $? -eq 0 ] && echo "start $pkg(Pid:$PID2) OK" || echo "start $pkg Fail"
sleep 3

done

2.war

#!/bin/bash
#
pkg_path=/tmp
run_path=/usr
uptime=`date +"%F"`

cd $run_path

pkgs=(api openapi sp pos)
for pkg in ${pkgs[@]}
do

rm -rf $pkg/webapps/ROOT
mv $pkg/webapps/ROOT.war $pkg_path/bak/$pkg.war.$uptime
cp $pkg_path/$pkg.war $pkg/webapps/ROOT.war

PID=`ps -ef|grep $run_path/$pkg|egrep -v grep|awk '{print $2}'`
if [ ! "$PID" = "" ]
then
	kill -9 $PID
	echo "KILL $PID:"
fi

sleep 2

./$pkg/bin/startup.sh

PID2=`ps -ef|grep $run_path/$pkg|egrep -v grep|awk '{print $2}'`
[ $? -eq 0 ] && echo "start $pkg(Pid:$PID2) OK" || echo "start $pkg Fail"
sleep 10

done

发表评论

电子邮件地址不会被公开。 必填项已用*标注