Jpom/script/Jpom.sh

133 lines
3.2 KiB
Bash
Raw Normal View History

2019-04-05 12:04:16 +08:00
# The MIT License (MIT)
#
2019-04-05 20:36:01 +08:00
# Copyright (c) 2019 码之科技工作室
2019-04-05 12:04:16 +08:00
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2019-01-03 17:43:53 +08:00
#!/bin/bash
Tag="KeepBx-System-JpomApplication"
2019-02-13 10:58:09 +08:00
MainClass="cn.keepbx.jpom.JpomApplication"
# 自动获取当前路径
Path=$(cd `dirname $0`; pwd)"/"
2019-02-28 20:07:21 +08:00
Lib="${Path}lib/"
Log="${Path}run.log"
LogBack="${Path}log/"
2019-01-03 17:43:53 +08:00
JVM="-server "
2019-02-28 14:24:00 +08:00
# 修改项目端口号 日志路径
2019-03-26 16:02:38 +08:00
ARGS="--server.port=2122 --jpom.log=${Path}log"
2019-01-03 17:43:53 +08:00
echo ${Tag}
RETVAL="0"
# 启动程序
2019-01-03 17:43:53 +08:00
function start() {
echo ${Log}
# 备份日志
2019-01-03 17:43:53 +08:00
if [[ -f ${Log} ]]; then
if [[ ! -d ${LogBack} ]];then
mkdir ${LogBack}
fi
cur_dateTime="`date +%Y-%m-%d_%H:%M:%S`.log"
mv ${Log} ${LogBack}${cur_dateTime}
echo "mv to $LogBack$cur_dateTime"
touch ${Log}
fi
2019-03-15 15:04:38 +08:00
# classPath
CLASSPATH=`listDir ${Lib}`
nohup java ${JVM} -classpath ${CLASSPATH}${JAVA_HOME}/lib/tools.jar -Dappliction=$Tag ${MainClass} ${ARGS} >> ${Log} 2>&1 &
2019-01-03 17:43:53 +08:00
tailf ${Log}
}
2019-03-15 15:04:38 +08:00
# 拼接所有文件
function listDir()
{
ALL=""
for file in `ls $1`
do
#得到文件的完整的目录
ALL="${ALL}${1}/${file}:"
done
echo ${ALL}
}
# 停止程序
2019-01-03 17:43:53 +08:00
function stop() {
pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
if [[ "$pid" != "" ]]; then
echo -n "boot ( pid $pid) is running"
echo
2019-03-01 17:33:41 +08:00
echo -n $"Shutting down boot: wait"
kill $(pgrep -f ${Tag}) 2>/dev/null
2019-02-22 13:32:24 +08:00
sleep 3
2019-01-03 17:43:53 +08:00
pid=$(ps -ef | grep -v 'grep' | egrep $Tag| awk '{printf $2 " "}')
if [[ "$pid" != "" ]]; then
echo "kill boot process"
kill -9 "$pid"
fi
2019-02-22 13:32:24 +08:00
else
echo "boot is stopped"
fi
2019-01-03 17:43:53 +08:00
status
}
# 获取程序状态
2019-01-03 17:43:53 +08:00
function status()
{
pid=$(ps -ef | grep -v 'grep' | egrep ${Tag}| awk '{printf $2 " "}')
#echo "$pid"
if [[ "$pid" != "" ]]; then
echo "boot is running,pid is $pid"
else
echo "boot is stopped"
fi
}
# 提示使用语法
2019-01-03 17:43:53 +08:00
function usage()
{
echo "Usage: $0 {start|stop|restart|status}"
RETVAL="2"
}
# See how we were called.
RETVAL="0"
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
RETVAL="3"
;;
status)
status
;;
*)
usage
;;
esac
exit $RETVAL