python web api部署服务器

一、写一个testapi.service文件,上传到/etc/systemd/system目录下

[Unit]
Description=My Python Web API
After=network.target

[Service]
User=liu
WorkingDirectory= /home/myuser/myapp/myproject
ExecStart=/home/myuser/myapp/venv/bin/python  /home/myuser/myapp/test.py
Restart=always

[Install]
WantedBy=multi-user.target

二、你可以通过以下命令检查该服务是否存在:

systemctl list-unit-files | grep testapi

运行后提示

systemctl list-unit-files | grep testapi
testapi.service disabled enabled

从你提供的输出来看,testapi服务存在,但是它处于禁用状态。你需要启用该服务,然后才能够使用它。

你可以使用以下命令启用该服务:

sudo systemctl enable testapi

然后,你可以使用以下命令启动该服务:

sudo systemctl start testapi

如果你还想在系统启动时自动启动该服务,你可以将其添加到启动项中:

sudo systemctl enable --now testapi

这将启用并立即启动该服务,并在系统启动时自动启动该服务。

sudo systemctl stop testapi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值