添加自启脚本内容

This commit is contained in:
haotian 2025-08-12 10:32:12 +08:00
parent e1a4fd17e3
commit 5cf830dfce
2 changed files with 10 additions and 10 deletions

View File

@ -4,7 +4,7 @@ Description=My Custom Startup Script
[Service]
User=pro
# 这里确保自己对这个脚本有执行权限。现chmod +x xxxx.sh
ExecStart=/home/pro/haotian/康达瑞贝斯/康达后台项目/start_sync_robot.sh
ExecStart=/home/pro/xxxx/run.sh
Restart=on-failure
WorkingDirectory=/home/pro/

18
run.sh
View File

@ -1,11 +1,11 @@
#! /bin/bash
__conda_setup="$('/home/admin-root/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
__conda_setup="$('/home/pro/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/admin-root/miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/admin-root/miniconda3/etc/profile.d/conda.sh"
if [ -f "/home/pro/miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/pro/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/home/pro/miniconda3/bin:$PATH"
fi
@ -16,7 +16,7 @@ unset __conda_setup
conda activate trt
# 进入到项目目录
cd /home/admin-root/haotian/康达瑞贝斯/康达后台项目
cd /home/pro/xxxx
LOG_DIR="logs/robot"
@ -28,16 +28,16 @@ LOG_FILE="$LOG_DIR/robot_$(date +%Y%m%d_%H%M%S).log"
# 检查当前程序是否已经正在运行.
if pgrep -f "run_sync_robot.py" > /dev/null; then
echo "run_sync_robot 已经在运行中"
if pgrep -f "faceApp.py" > /dev/null; then
echo "faceApp 已经在运行中"
exit 1
fi
# nohup python run_sync_robot.py > "$LOG_FILE" 2>&1 &
# 注systemctl控制时最后的&要去掉,使得脚本一直在运行.脚本其实阻塞在这,后面都不会执行
nohup python run_sync_robot.py > "$LOG_FILE" 2>&1
nohup python faceApp.py > "$LOG_FILE" 2>&1
# 保存进程id
echo $! > "$LOG_DIR/robot.pid"
echo $! > "$LOG_DIR/faceApp.pid"
echo "WebSocket客户端已启动日志保存在: $LOG_FILE"
echo "进程ID: $(cat $LOG_DIR/robot.pid)"
echo "进程ID: $(cat $LOG_DIR/faceApp.pid)"