#!/usr/bin/env bash APP_NAME=spring-boot-service APP_HOME=$(dirname $(pwd))/${APP_NAME} PID_FILE=${APP_HOME}/pid LOG_FILE=/dev/null #${APP_HOME}/logs/console.out JAVA_OPTS=-Xms512m BOOST_JAR=${APP_NAME}.jar PROFILE='' mkdir -p ${APP_HOME}/logs # if [ ! -f "$PID_FILE" ]; then touch "$PID_FILE" echo 0 > ${PID_FILE} fi pid=0 #========================= getpid(){ #pid=`cat ${PID_FILE}` pid=`ps -ef | grep ${BOOST_JAR} | grep -v grep | awk '{print $2}'` if [ -z ${pid} ]; then pid=0 fi } #========================== run() { if [ ${pid} -ne 0 ]; then echo "================================" echo "already started!" echo "================================" exit 1 fi java -server ${JAVA_OPTS} ${PROFILE} -jar ${BOOST_JAR} } #========================== start() { getpid nohup java -server ${JAVA_OPTS} ${PROFILE} -jar ${BOOST_JAR} >> ${LOG_FILE} 2>&1 & echo $! > ${PID_FILE} echo "Starting..." getpid if [ ${pid} -ne 0 ]; then echo "================================" echo "[Start Success] (pid=$pid)" echo "================================" else echo "================================" echo "[Start Failed]" echo "================================" fi } #========================== stop() { getpid if [ ${pid} -ne 0 ]; then echo "killing ${pid}" skill -15 ${pid} echo "================================" echo "stoping" echo "================================" echo 0 > ${PID_FILE} else echo "no running process" fi } #========================== case "$1" in 'run') run ;; 'start') start ;; 'stop') stop ;; *) echo "Usage: $0 {run|start|stop}" exit 1 esac exit 0
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END