forked from dunwu/java-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembed-tomcat-server-boot.sh
More file actions
90 lines (81 loc) · 2.42 KB
/
embed-tomcat-server-boot.sh
File metadata and controls
90 lines (81 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#################################################################################
# 嵌入式 Tomcat 应用启动脚本
#################################################################################
# 删除旧日志文件
removeOldLog() {
mkdir -p /home/zp/log/startup
if [ -f $LOG_FILE ];then
rm -rf $LOG_FILE
fi
}
# 检查脚本参数,如必要参数未传入,退出脚本。
checkInput() {
if [ "${app}" == "" ] || [ "${oper}" == "" ] || [ "${javaArgs}" == "" ] || [ "${classpathArgs}" == "" ] || [ "${bootstrapClass}" == "" ]; then
echo "请输入脚本参数:app oper javaArgs classpathArgs bootstrapClass"
echo " app: 应用名。"
echo " oper: 运行环境(必填)。可选值:start|stop|restart"
echo " javaArgs: JVM 参数(必填)。"
echo " classpathArgs: classpath参数(必填)。"
echo " bootstrapClass: 启动类(必填)。"
exit 0
fi
}
# 检查服务是否已经启动
PIDS=""
checkStarted() {
PIDS=`ps -ef | grep java | grep ${app} | awk '{print $2}'`
if [ -n "$PIDS" ]; then
return 0
else
return 1
fi
}
execOper() {
case "${oper}" in
start)
echo -n "starting server: "
#检查服务是否已经启动
# if checkStarted ;then
# echo "ERROR: server already started!"
# echo "PID: $PIDS"
# exit 1
# fi
args="${javaArgs} -classpath ${classpathArgs} ${bootstrapClass}"
#echo -e "启动参数:\n${args}"
#启动服务
nohup java ${args} > ${LOG_FILE} 2>&1 &
# echo -e "执行参数:\n${args}"
echo -e "\nthe server is started..."
;;
stop)
echo -n "stopping server: "
#dubbo提供优雅停机, 不能使用kill -9
if checkStarted ;then
kill $PIDS
echo -e "\nthe server is stopped..."
else
echo -e "\nno server to be stopped..."
fi
;;
restart)
$0 ${app} stop "${javaArgs}" "${classpathArgs}" "${bootstrapClass}"
sleep 5
$0 ${app} start "${javaArgs}" "${classpathArgs}" "${bootstrapClass}"
;;
*)
echo "Invalid oper: ${oper}."
exit 1
esac
}
######################################## MAIN ########################################
# 获取输入参数
app=`echo $1`
oper=`echo $2`
javaArgs=`echo $3`
classpathArgs=`echo $4`
bootstrapClass=`echo $5`
vars=$*
checkInput
LOG_FILE=/home/zp/log/startup/${app}-startup.log
removeOldLog
execOper