易错提示:开机自启这快,试了好多方法,出错的原因是没有source conda.sh脚本,大家在做时,可以看下是否是因为出现了这种问题。
为什么需要手动加载它?
在非交互式的 Shell(例如 rc.local
或 systemd
)中,默认情况下不会加载用户的环境配置文件(如 .bashrc
或 .profile
),因此无法找到 conda
命令。而手动加载 conda.sh
脚本可以确保 conda
命令在非交互式 Shell 中也能正常使用。
采用systemd服务方法
1,创建xinference.sh文件
sudo vim /etc/systemd/system/xinference.service
2,在文件中添加以下内容
[Unit]
Description=Xinference Service
After=network.target
[Service]
Type=simple
ExecStart=/bin/bash -c 'source /root/miniconda3/etc/profile.d/conda.sh && conda activate xinference_env310 && cd /root/ai && XINFERENCE_MODEL_SRC=modelscope xinference-local --host 0.0.0.0 --port 9997 > xinference.log 2>&1'
Restart=on-failure
[Install]
WantedBy=multi-user.target
3,启用并启动服务
sudo systemctl daemon-reload
sudo systemctl enable xinference.service
sudo systemctl start xinference.service
4,重启测试
重启系统,查看服务是否重新启动
sudo reboot