添加自启脚本

This commit is contained in:
haotian 2025-09-30 15:23:13 +08:00
parent 88584338a3
commit 424f6582ba
2 changed files with 45 additions and 0 deletions

16
face_rec.service Normal file
View File

@ -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

29
start.sh Executable file
View File

@ -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)"