From 424f6582bae4afaa71ef940e5c75d888cad68306 Mon Sep 17 00:00:00 2001 From: haotian <2421912570@qq.com> Date: Tue, 30 Sep 2025 15:23:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=90=AF=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- face_rec.service | 16 ++++++++++++++++ start.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 face_rec.service create mode 100755 start.sh diff --git a/face_rec.service b/face_rec.service new file mode 100644 index 0000000..9b06cc1 --- /dev/null +++ b/face_rec.service @@ -0,0 +1,16 @@ +[Unit] +Description=My Custom Startup Script + +[Service] +Type=simple +User=unitree +# 配置systemd服务允许访问显示 +Environment="DISPLAY=:1" +Environment="XAUTHORITY=/home/unitree/.Xauthority" +# 这里确保自己对这个脚本有执行权限。现chmod +x xxxx.sh +ExecStart=/home/unitree/robot_face_rec/start.sh +Restart=on-failure +WorkingDirectory=/home/unitree/ + +[Install] +WantedBy=multi-user.target diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..cea0223 --- /dev/null +++ b/start.sh @@ -0,0 +1,29 @@ +#! /bin/bash + + +# 进入到项目目录 +cd /home/unitree/robot_face_rec + + +LOG_DIR="logs/face_rec" + +mkdir -p $LOG_DIR + +# 生成日志文件名(使用当前时间) +LOG_FILE="$LOG_DIR/robot_$(date +%Y%m%d_%H%M%S).log" + +# 检查当前程序是否已经正在运行. + +if pgrep -f "face_rec.py" > /dev/null; then + echo "face_rec.py 已经在运行中" + exit 1 +fi + +# nohup python run_sync_robot.py > "$LOG_FILE" 2>&1 & +# 注systemctl控制时最后的&要去掉,使得脚本一直在运行.脚本其实阻塞在这,后面都不会执行 +nohup python face_rec.py > "$LOG_FILE" 2>&1 + +# 保存进程id +echo $! > "$LOG_DIR/robot.pid" +echo "WebSocket客户端已启动,日志保存在: $LOG_FILE" +echo "进程ID: $(cat $LOG_DIR/robot.pid)" \ No newline at end of file