Skip to content

Commit 3132aae

Browse files
author
gclm
committed
fix(jenkins 脚本)
1 parent febf0e3 commit 3132aae

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

scripts/app.sh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
3+
# Java ENV(此处需要修改,需要预先安装JDK)
4+
export JAVA_HOME=/usr/local/jdk
5+
export JRE_HOME=${JAVA_HOME}/jre
6+
7+
# Apps Info
8+
# 应用存放地址(此处需要修改)
9+
APP_HOME=$(pwd)
10+
# 应用名称
11+
APP_NAME=$1
12+
13+
# Shell Info
14+
15+
# 使用说明,用来提示输入参数
16+
usage() {
17+
echo "Usage: sh boot [APP_NAME] [start|stop|restart|status]"
18+
exit 1
19+
}
20+
21+
# 检查程序是否在运行
22+
is_exist(){
23+
# 获取PID
24+
PID=$(ps -ef |grep ${APP_NAME} | grep -v $0 |grep -v grep |awk '{print $2}')
25+
# -z "${pid}"判断pid是否存在,如果不存在返回1,存在返回0
26+
if [ -z "${PID}" ]; then
27+
# 如果进程不存在返回1
28+
return 1
29+
else
30+
# 进程存在返回0
31+
return 0
32+
fi
33+
}
34+
35+
# 定义启动程序函数
36+
start(){
37+
is_exist
38+
if [ $? -eq "0" ]; then
39+
echo "${APP_NAME} is already running, PID=${PID}"
40+
else
41+
nohup ${JRE_HOME}/bin/java -jar ${APP_HOME}/${APP_NAME} >/dev/null 2>&1 &
42+
PID=$(echo $!)
43+
echo "${APP_NAME} start success, PID=$!"
44+
fi
45+
}
46+
47+
# 停止进程函数
48+
stop(){
49+
is_exist
50+
if [ $? -eq "0" ]; then
51+
kill -9 ${PID}
52+
echo "${APP_NAME} process stop, PID=${PID}"
53+
else
54+
echo "There is not the process of ${APP_NAME}"
55+
fi
56+
}
57+
# 重启进程函数
58+
restart(){
59+
stop
60+
start
61+
}
62+
63+
# 查看进程状态
64+
status(){
65+
is_exist
66+
if [ $? -eq "0" ]; then
67+
echo "${APP_NAME} is running, PID=${PID}"
68+
else
69+
echo "There is not the process of ${APP_NAME}"
70+
fi
71+
}
72+
73+
case $2 in
74+
"start")
75+
start
76+
;;
77+
"stop")
78+
stop
79+
;;
80+
"restart")
81+
restart
82+
;;
83+
"status")
84+
status
85+
;;
86+
*)
87+
usage
88+
;;
89+
esac
90+
exit 0

0 commit comments

Comments
 (0)