ubuntu配置gunicorn开机启动

需求

需要开机运行项目,使用systemctl来控制gunicorn开机启动

systemctl配置文件

/usr/lib/systemd/system/下增加文件project.service,文件名根据需要命名,以.service结尾,文件内容:

[Unit]
# 描述
Description=gunicorn for n20
# 在网络服务启动后再启动
After=network.target

[Service]
User=nvidia
# 项目文件目录
WorkingDirectory=/var/www/wifi
# gunicorn启动命令
ExecStart=/usr/bin/sudo /home/nvidia/.local/bin/gunicorn app:app -w 1 -b 0.0.0.0:8000
# 错误重启
Restart=on-failure

[Install]
WantedBy=multi-user.target

启动命令

配置好配置文件后,需要执行命令启动服务

# 重新加载配置文件
sudo systemctl daemon-reload
# 开启服务
sudo systemctl start n20.service
# 查看服务状态
sudo systemctl status n20.service
# 设置开机启动
sudo systemctl enable n20.service
posted @ 2021-08-01 10:56  守望人间  阅读(873)  评论(0编辑  收藏  举报