1.启动脚本
start.sh
#!/bin/bash
nohup java -Xmx512m -Xms128m -jar /home/apps/SzjjServices/SzjjServices-1.0.0.jar >/dev/null 2>&1 &
2.关闭脚本
stop.sh
#!/bin/bash
pid=`ps -ef | grep "Szjj" | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
#kill -9 强制终止
echo "kill 的pid:" $pid
kill $pid
fi
echo "命令运行结束"
3.jenkins可以用的部署脚本
deploy.sh
#!/bin/bash
if [ ! -n "$1" ] ;then
echo "请输入项目名!"
exit 1
fi
echo "Execute shell Start..."
project_name=$1
dir=/root/.jenkins/workspace/$project_name/target
cd $dir
str=`find -name '*.jar'`
jar_name=${str#*/}
echo "jar包名字为:"$jar_name
#检查是否已经启动
pid=`ps -ef | grep $jar_name | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
#kill -9 强制终止
echo "kill -9 的pid:" $pid
kill -9 $pid
fi
file="/usr/local/"${jar_name}
cp -f $dir/$jar_name /usr/local/$jar_name
#部署
BUILD_ID=dontKillMe nohup java -jar /usr/local/$jar_name >/dev/null 2>&1 &
echo "Execute shell Finish"
使用方法:sh deploy.sh projectName