#!/bin/sh # # source /etc/profile PROC_STR="gnyy-v" SERVICE_HOME="/home/xlk/marketing-cloud/service" LOG="$SERVICE_HOME/logs/service.log" JAR=$(ls -lt ${SERVICE_HOME}/*.jar|head -n1|rev|cut -d" " -f1|rev) LIBS="$SERVICE_HOME/libs" CONFIG_PATH="$SERVICE_HOME/config/" # must be end with / start() { PID=`ps -ef|grep $PROC_STR|grep -v grep|awk '{print $2}'` if [[ "$PID" != "" ]]; then echo "" echo "Service is running. pid=$PID" echo "" exit 0 else echo "" echo "Start service ..." echo "FILE: $JAR" nohup java -Dloader.path=$LIBS -jar $JAR --spring.config.location=$CONFIG_PATH > $LOG 2>&1 & echo "Start finished" echo "Pls goto $LOG see process status" echo "" fi } stop() { echo "" echo "Stoping service ..." PID=`ps -ef|grep $PROC_STR|grep -v grep|awk '{print $2}'` if [[ "$PID" != "" ]]; then kill -9 $PID fi # 这个延迟不能去掉 sleep 2s echo "Service is stoped" echo "" } case $1 in "start") start ;; "stop") stop ;; "reload"|"restart") stop start ;; *) echo "Usage: `basename $0` {start|stop|restart}" exit 1 esac