我想从CLI启动一个Web应用程序,就像这样:
user@server:~$ my_app web --startWeb项目是用水瓶座开发的,我想要在deamon模式下执行带有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发布于 2018-02-12 17:53:56
我用os.chdir(here)解决了这个问题,其中这里是是wsgi模块所在的当前目录。
如下所示(server.py):
import os
import subprocess
here = os.path.abspath(os.path.dirname(__file__))
def start_server():
os.chdir(here)
command = "gunicorn --bind 0.0.0.0:8000 wsgi:app --daemon"
subprocess.call(command, shell=True)目录结构是:
├── my_app
│ ├── cli
│ │ ├── cli_app.py
│ │ ├── __init__.py
│ ├── helpers.py
│ ├── __version__.py
│ └── web
│ ├── __init__.py
│ ├── services.py
│ ├── static/
│ ├── templates/
│ │ ├── index.html
│ ├── server.py
│ ├── wsgi.pyhttps://stackoverflow.com/questions/48510770
复制相似问题