1、通用脚本
#!/bin/bash
cd /opt/silentcall
chmod 777 *.sh
sh stop.sh
sh replace.sh
BUILD_ID=dontKillMe sh start.sh
2、replace.sh
#!/bin/bash
jar_name=silentcall-server-0.0.1-SNAPSHOT.jar
#编译好的jar包存放地址
file_path=/var/lib/jenkins/workspace/silentcall_project/silentcall/silentcall-server/target
#将现有的jar备份后,将新的jar包替换
file="/opt/silentcall/silentcall-server-0.0.1-SNAPSHOT.jar"
if [ -f "$file" ]
then
mv $file /opt/silentcall_backup/$jar_name.`date +%Y%m%d%H%M%S`
fi
rm -rf $file
cp $file_path/$jar_name /opt/silentcall
3、start.sh
#!/bin/bash
echo "授权当前用户"
chmod 777 /opt/silentcall/silentcall-server-0.0.1-SNAPSHOT.jar
echo "执行...."
cd /opt/silentcall/
nohup java -jar silentcall-server-0.0.1-SNAPSHOT.jar &
echo "启动成功"