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
| source /etc/profile
JAVA_HOME=/此处换成真实jdk路径 export PATH=$PATH:$JAVA_HOME/bin export BUILD_ID=dontkillme
PROJECT_NAME=此处换成真实jar名称.jar LOG_NAME=日志名.log
isExist() { pid=$(ps -ef | grep ${PROJECT_NAME} | grep -v "grep" | awk '{print $2}') echo "${pid}" if [ -z "${pid}" ]; then return 0 else return 1 fi }
start() { isExist if [ $? -eq "0" ]; then echo "${PROJECT_NAME} is starting ......" nohup java -jar ${PROJECT_NAME} --spring.profiles.active=prod >${LOG_NAME} 2>&1 & echo "${PROJECT_NAME} startup success" else echo "${PROJECT_NAME} is already running, pid=${pid}" restart fi }
stop() { isExist if [ $? -eq "0" ]; then echo "${PROJECT_NAME} is not running ......" else echo "${PROJECT_NAME} is already running, pid=${pid}, prepare kill it " kill -9 ${pid} echo "${PROJECT_NAME} has been successfully killed ......" fi }
restart() { stop start }
case "$1" in "start") start ;; "stop") stop ;; "restart") restart ;; *) echo "please enter the correct commands: " echo "such as : sh startup.sh [ start | stop | restart ]" ;; esac
|