编写服务文件:sudo nano /etc/systemd/system/run-ai_yujing.service
[Unit]
Description=AI YuJing System Startup Script
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/home/user/ai_yujing
Environment="PATH=/usr/local/cuda-12.6/bin:/home/user/anaconda3/envs/cv2h264/bin:/home/user/anaconda3/condabin:/usr/local/cuda-12.6/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
ExecStart=/bin/bash -c 'source /home/user/anaconda3/etc/profile.d/conda.sh && conda activate cv2h264 && cd /home/user/ai_yujing && sudo -S ls <<< "你的user用户的密码" && nohup java -jar gx-admin.jar & cd /home/user/ai_yujing/video-detect && python flaskserver.py'
Restart=always
[Install]
WantedBy=multi-user.target
- 其中
Environment
项可以在切换到对应conda虚拟环境后用printenv
命令查看