yum install redhat-lsb -y
进入/usr/local/bin
放入脚本springboot
添加权限
chmod +x springboot
####################################
#!/bin/bash
. /etc/profile
if [ -r /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
else
exit 1
fi
NAME="$(basename $0)"
function usage()
{
echo "Usage: $0 {start|stop|restart} {mkt-web|eshop-app}"
RETVAL="2"
}
if [ $# -ne 2 ]; then
usage
exit 1
fi
APP=$2
if [ -z $APP -o ! -d "/data/springboot/$APP" ];then
echo "Null parameter or $APP not exists"
exit 1
fi
SPRINGBOOT_HOME="/data/springboot/$APP"
function start() {
echo "Starting ${APP}: "
if [ "$RETVAL" != "0" ];then
log_failure_msg
return
fi
pid=$(ps aux | grep "${SPRINGBOOT_HOME}" | grep -v "grep" | awk '{print $2}')
if [ -n "$pid" ];then
log_success_msg "is running, PID: $pid"
return
fi
nohup java -jar ${SPRINGBOOT_HOME}/$APP.jar > ${SPRINGBOOT_HOME}/$APP.log 2>&1 &
sleep 3
pid=$(ps aux | grep "${SPRINGBOOT_HOME}" | grep -v "grep" | awk '{print $2}')
if [ -z "$pid" ];then
log_failure_msg
RETVAL=1
else
log_success_msg "PID: $pid"
fi
}
function stop() {
echo -n "Stopping ${APP}: "
pid=$(ps aux | grep "${SPRINGBOOT_HOME}" | grep -v grep | awk '{print $2}')
if [ -z "$pid" ];then
echo -n "not running"
log_warning_msg
return
fi
count=0
until [ -z "$(ps aux | grep "${SPRINGBOOT_HOME}" | grep -v grep | awk '{print $2}')" ] || [ $count -gt 3 ];
do
kill -9 $pid
sleep 3
let count="${count}+1"
done
if [ $count -gt 3 ];then
RETVAL=1
log_failure_msg "PID: $pid"
return 1
else
rm -rf /data/springboot/$APP/work/*
rm -rf /data/springboot/$APP/temp/*
log_success_msg "PID: $pid"
fi
}
RETVAL="0"
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
usage
;;
esac
exit $RETVAL
####################################
文件放置目录/data/springboot/$APP/$APP.jar
启动命令:springboot start $APP