赞
踩
Linux Java服务管理脚本(启动、停止、查看状态)
vim service.sh
JAR_FLE 填写jar包的文件名!!!
- #!/bin/bash
-
- JAR_FILE=quanzhou-driver-ai-api-0.0.1-SNAPSHOT.jar
-
- usage() {
- echo "Usage: $0 {start|stop|status}"
- echo ""
- echo "Options:"
- echo " start Start the service."
- echo " stop Stop the service."
- echo " status Check the service status."
- echo ""
- }
-
- if [ -z "$1" ]; then
- usage
- exit 1
- fi
-
-
- case "$1" in
- start)
- echo "Starting service with JAR file: $JAR_FILE"
- nohup java -Dspring.profiles.active=test -jar $JAR_FILE > /dev/null 2>&1 &
- PID=$(pgrep -f "$JAR_FILE")
- echo "Service started successfully with PID: $PID"
- ;;
- stop)
- echo "Stopping service..."
- PID=$(pgrep -f "$JAR_FILE")
- if [ -z "$PID" ]; then
- echo "No running process found."
- else
- kill -9 $PID
- echo "Service stopped successfully with PID: $PID"
- fi
- ;;
-
- status)
- PID=$(pgrep -f "$JAR_FILE")
- if [ -z "$PID" ]; then
- echo "Service is not running."
- else
- echo "Service is running with PID: $PID"
- fi
- ;;
- *)
- usage
- exit 1
- ;;
- esac
-
- exit 0

- esc 退出编辑模式
-
- :wq 保存修改
chmod +x service.sh
- ./service.sh start 启动服务
- ./service.sh stop 停止服务
- ./service.sh status 查看状态
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。