diff --git a/shell/advisor-server.service b/shell/advisor-server.service new file mode 100644 index 0000000..a093e9a --- /dev/null +++ b/shell/advisor-server.service @@ -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 \ No newline at end of file diff --git a/shell/clear_log.sh b/shell/clear_log.sh new file mode 100644 index 0000000..f513dfb --- /dev/null +++ b/shell/clear_log.sh @@ -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." \ No newline at end of file diff --git a/shell/kill.sh b/shell/kill.sh new file mode 100644 index 0000000..c5ed76a --- /dev/null +++ b/shell/kill.sh @@ -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 \ No newline at end of file diff --git a/shell/start.sh b/shell/start.sh new file mode 100644 index 0000000..d38a44a --- /dev/null +++ b/shell/start.sh @@ -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 \ No newline at end of file diff --git a/start.sh b/start.sh deleted file mode 100644 index 9b35211..0000000 --- a/start.sh +++ /dev/null @@ -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 -