#!/bin/bash # 定义变量 APP_NAME="ims" APP_JAR="/ims/app/ims.jar" # 替换为你的 JAR 包路径 CONFIG_FILE="/ims/app/application.yml" # 替换为你的配置文件路径 LOG_FILE="/ims/app/ims.log" # 日志文件路径 PID_FILE="/ims/app/ims.pid" # 保存进程 ID 的文件 # 启动函数 start() { if [ -f "$PID_FILE" ]; then PID=$(cat "$PID_FILE") if ps -p "$PID" > /dev/null; then echo "Application $APP_NAME is already running with PID $PID." exit 1 else rm -f "$PID_FILE" fi fi echo "Starting $APP_NAME..." nohup java -jar "$APP_JAR" --spring.config.location="$CONFIG_FILE" > "$LOG_FILE" 2>&1 & echo $! > "$PID_FILE" echo "Application $APP_NAME started with PID $!." } # 停止函数 stop() { if [ -f "$PID_FILE" ]; then PID=$(cat "$PID_FILE") if ps -p "$PID" > /dev/null; then echo "Stopping $APP_NAME with PID $PID..." kill "$PID" rm -f "$PID_FILE" echo "Application $APP_NAME stopped." else echo "Application $APP_NAME is not running." rm -f "$PID_FILE" fi else echo "PID file not found. Application $APP_NAME may not be running." fi } # 重启函数 restart() { stop sleep 2 start } # 脚本入口 case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 ;; esac exit 0