一、项目需求:
1、在Ubuntu Linux 22.04 LTS 版本的系统是部署开机自启动service;
2、通过widows11与Ubuntu Linux 22.04进行Post请求;
3、启动python的服务,在指定的conda环境下运行代码。
二、实施流程:
1、创建运行脚本
#在目标目录创建一个脚本
sudo vim auto_run.sh
2、自动执行内容
然后在auto_rune.sh中贴入下面的内容:Anaconda 安装目录及 activate 脚本的具体目录位置,需要替换成你的安装路径;之后切换到你的项目的根目录;
使用 Python 指令运行目标 Python 程序;
#!/bin/bash
# activate conda env
source /home/user/anaconda3/bin/activate fastapi
# use target path
cd /home/user/Python/code/
python FastAPI.py
3、建立一个Service
#在目标目录创建一个 Service 文件
sudo vim auto_run.service
#贴入下面的内容:
[Unit]
Description=Run FastAPI service at Startup
After=network.target
[Service]
ExecStart=/home/user/Python/code/auto_run.sh
User=root
Group=root
Restart=always
[Install]
WantedBy=multi-user.target
#Afte

444

被折叠的 条评论
为什么被折叠?



