【发布时间】:2018-07-08 17:02:15
【问题描述】:
我想从类似的 CLI 启动一个 Web 应用程序:
user@server:~$ my_app web --start
Web 项目是使用 Flask 开发的,我想在守护模式下使用 gunicorn 执行 Web 应用程序。
但我不明白如何从 python 模块执行 gunicorn 命令。命令是:
user@server:~$ gunicorn --bind 0.0.0.0:8000 wsgi:app --daemon
我想到了以下功能:
def start_server():
command = "gunicorn --bind 0.0.0.0:8000 wsgi:app --daemon"
subprocess.call(command, shell=True)
显然它不起作用。我想要一些允许我从 python 模块控制服务器(启动、状态、停止等)的东西。有可能吗?
项目结构:
├── my_app
│ ├── cli
│ │ ├── cli_app.py
│ │ ├── __init__.py
│ ├── helpers.py
│ ├── __version__.py
│ └── web
│ ├── __init__.py
│ ├── services.py
│ ├── static/
│ ├── templates/
│ │ ├── index.html
│ ├── services.py
│ ├── wsgi.py
【问题讨论】: