更新脚本

This commit is contained in:
easonzhu 2025-02-21 14:41:18 +08:00
parent 504c52b364
commit 0e38ab0bb6
5 changed files with 72 additions and 31 deletions

View File

@ -0,0 +1,21 @@
[Unit]
Description=Advisor Server
After=network.target
[Service]
User=root
WorkingDirectory=/root
ExecStart=/usr/bin/java -Xms2g -Xmx2g -XX:+UseG1GC -jar /root/AdvisorServer-2.6.7.jar --spring.profiles.active=prod
Restart=always
StandardOutput=append:/root/advisor_server.log
StandardError=append:/root/advisor_server.log
LimitNOFILE=8192
RestartSec=120
StartLimitInterval=600
StartLimitBurst=5
TimeoutStartSec=300
MemoryMax=3G
CPUQuota=200%
[Install]
WantedBy=multi-user.target

9
shell/clear_log.sh Normal file
View File

@ -0,0 +1,9 @@
#!/bin/bash
# 设置日志文件所在目录
log_dir="/root/logs"
# 查找并删除超过 7 天的日志文件
find "$log_dir" -name "advisor_server*.log" -type f -mtime +7 -exec rm -f {} \;
echo "Old logs older than 7 days have been deleted."

17
shell/kill.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/bash
# 检查服务是否正在运行
status=$(systemctl is-active advisor-server.service)
if [ "$status" == "active" ]; then
# 如果服务已经在运行,重启服务
echo "AdvisorServer is running. Stopping the service..."
systemctl stop advisor-server.service
if [ $? -eq 0 ]; then
echo "AdvisorServer stopped successfully."
else
echo "Failed to stop AdvisorServer."
fi
else
echo "AdvisorServer is not running."
fi

25
shell/start.sh Normal file
View File

@ -0,0 +1,25 @@
#!/bin/bash
log_file="/root/advisor_server.log"
# 检查服务是否正在运行
status=$(systemctl is-active advisor-server.service)
if [ "$status" == "active" ]; then
# 如果服务已经在运行,重启服务
echo "AdvisorServer is running. Restarting the service..."
systemctl restart advisor-server.service
if [ $? -eq 0 ]; then
echo "AdvisorServer restarted successfully."
else
echo "Failed to restart AdvisorServer."
fi
else
echo "AdvisorServer is not running. Starting the service..."
systemctl start advisor-server.service
if [ $? -eq 0 ]; then
echo "AdvisorServer started successfully."
else
echo "Failed to start AdvisorServer."
fi
fi

View File

@ -1,31 +0,0 @@
#!/bin/bash
# 获取当前日期格式yyyyMMdd
current_date=$(date +"%Y%m%d")
# 日志文件名,包含日期
log_file="advisor_server_${current_date}.log"
# 查找包含 AdvisorServer 的进程
pid=$(ps aux | grep 'AdvisorServer' | grep -v 'grep' | awk '{print $2}')
if [ -n "$pid" ]; then
# 如果找到了进程,则杀掉它
echo "Found process with PID $pid. Killing the process..."
kill -9 $pid
if [ $? -eq 0 ]; then
echo "Process $pid terminated successfully."
else
echo "Failed to terminate process $pid."
fi
else
echo "No process found for AdvisorServer."
fi
# 使用 nohup 启动 jar 包,并设置 JVM 内存参数,同时保存日志,追加输出
echo "Starting /root/AdvisorServer-2.6.7.jar with JVM memory parameters..." >> "$log_file" 2>&1
nohup java -Xms2g -Xmx2g -XX:+UseG1GC -jar AdvisorServer-2.6.7.jar --spring.profiles.active=prod >> "$log_file" 2>&1 &
echo "AdvisorServer-2.6.7.jar started in background with nohup." >> "$log_file" 2>&1