适用于前后台分离的服务
一个jar包 一个前台工程
实现自动杀端口,复制文件,备份数据,发布新版本。
脚本复制到Linux中
【./jb.sh】按Enter运行即可
内容如下:
#自定义存放的地方
#文件存放的根目录
latestDir=/home/xnj
#jar包名字
jarName=swWeb.jar
#前端压缩包文件名
qdZipName=Desktop.zip
#前端tomcat的位置
qdTomcatPosition=/home/tomcat/apache-tomcat-8.5.43/webapps/ROOT
#脚本存放的位置
jbFilePosition=/home/jb
#结束
#年
year=$(date +%Y)
#月
month=$(date +%Y%m)
#日
day=$(date +%Y%m%d)
#时分秒
hms=$(date +%H%M%S)
#当前目录
currentDir=$(pwd)
#cd到当前目录
cd $jbFilePosition
#创建年目录
if [ ! -d $latestDir ]; then
mkdir $latestDir
fi
if [ ! -d
l
a
t
e
s
t
D
i
r
/
latestDir/
latestDir/year ]; then
mkdir
l
a
t
e
s
t
D
i
r
/
latestDir/
latestDir/year
fi
if [ ! -d
l
a
t
e
s
t
D
i
r
/
latestDir/
latestDir/year/$month ]; then
mkdir
l
a
t
e
s
t
D
i
r
/
latestDir/
latestDir/year/$month
fi
if [ ! -d
l
a
t
e
s
t
D
i
r
/
latestDir/
latestDir/year/
m
o
n
t
h
/
month/
month/day ]; then
mkdir
l
a
t
e
s
t
D
i
r
/
latestDir/
latestDir/year/
m
o
n
t
h
/
month/
month/day
fi
if [ ! -d
l
a
t
e
s
t
D
i
r
/
latestDir/
latestDir/year/
m
o
n
t
h
/
month/
month/day/$hms ]; then
mkdir
l
a
t
e
s
t
D
i
r
/
latestDir/
latestDir/year/
m
o
n
t
h
/
month/
month/day/KaTeX parse error: Expected 'EOF', got '#' at position 9: hms fi #̲将当前目录的下的jar包和前端…jarName
l
a
t
e
s
t
D
i
r
/
latestDir/
latestDir/year/
m
o
n
t
h
/
month/
month/day/
h
m
s
c
p
−
r
.
/
hms cp -r ./
hmscp−r./qdZipName
l
a
t
e
s
t
D
i
r
/
latestDir/
latestDir/year/
m
o
n
t
h
/
month/
month/day/$hms
#杀掉进程 awk是 是处理行数据的 xargs 是多个命令的连接的管道
ps -ef | grep $jarName | grep -v grep | awk ‘{print $2}’ | xargs kill -9
#删除前台工程
rm -rf
q
d
T
o
m
c
a
t
P
o
s
i
t
i
o
n
/
qdTomcatPosition/
qdTomcatPosition/qdZipName
rm -rf $qdTomcatPosition/static
rm -rf KaTeX parse error: Expected 'EOF', got '#' at position 29: …ion/index.html #̲加载新前台工程 cp -r .…qdZipName $qdTomcatPosition/
cd
q
d
T
o
m
c
a
t
P
o
s
i
t
i
o
n
u
n
z
i
p
.
/
qdTomcatPosition unzip ./
qdTomcatPositionunzip./qdZipName
#启动新的jar包
nohup java -jar
l
a
t
e
s
t
D
i
r
/
latestDir/
latestDir/year/
m
o
n
t
h
/
month/
month/day/
h
m
s
/
hms/
hms/jarName >nohup.out &