gunicorn:在描述的情况下是否有更好的方法来重新加载 gunicorn?
gunicorn: Is there a better way to reload gunicorn in described situation?
我有一个带有 gunicorn 和 nginx 的 django 项目。
我正在使用 saltstack 部署这个项目
在这个项目中,我有一个 django 视图读取的 config.ini
文件。
在 nginx 的情况下,如果 nginx.conf
发生变化,状态 cmd.run service nginx restart
和 - onchanges - file: nginx_conf
将重新启动服务。
但如果是 gunicorn,我可以检测到 config.ini
的变化,但我不知道如何重新加载 gunicorn。
当 gunicorn 启动时,我给了一个选项 --reload
但是这个选项是否检测到 config.ini
的变化不仅是 django 项目的文件'?
如果没有,我应该使用什么命令? (例如:gunicorn reload
)??
谢谢。
ps。我看到 kill -HUP pid
但我认为 salt 不知道 gunicorn 的 pid..
--reload
选项查找对源代码而非配置的更改。而且 --reload
无论如何都不应该在生产中使用。
我会:
1) 告诉 gunicorn 用 --pid /path/to/pid/file
写一个 pid 文件,然后用 salt 杀死 pid 然后重启。
2) 将 salt 添加到 运行 a pkill gunicorn
然后重新启动。
不要运行shell命令来管理服务,使用service
状态。
/path/to/nginx.conf:
file.managed:
# ...
/path/to/config.ini:
file.managed:
# ...
nginx:
service.running:
- enabled: true
- watch:
- file: /path/to/nginx.conf
django-app:
service.running:
- enabled: true
- reload: true
- watch:
- file: /path/to/config.ini
您可能需要自己为 gunicorn 创建服务定义。这是一个非常基本的 systemd 示例:
[Unit]
Description=My django app
After=network.target
[Service]
Type=notify
User=www-data
Group=www-data
WorkingDirectory=/path/to/source
ExecStart=/path/to/venv/bin/python gunicorn project.wsgi:application
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
[Install]
WantedBy=multi-user.target
我有一个带有 gunicorn 和 nginx 的 django 项目。
我正在使用 saltstack 部署这个项目
在这个项目中,我有一个 django 视图读取的 config.ini
文件。
在 nginx 的情况下,如果 nginx.conf
发生变化,状态 cmd.run service nginx restart
和 - onchanges - file: nginx_conf
将重新启动服务。
但如果是 gunicorn,我可以检测到 config.ini
的变化,但我不知道如何重新加载 gunicorn。
当 gunicorn 启动时,我给了一个选项 --reload
但是这个选项是否检测到 config.ini
的变化不仅是 django 项目的文件'?
如果没有,我应该使用什么命令? (例如:gunicorn reload
)??
谢谢。
ps。我看到 kill -HUP pid
但我认为 salt 不知道 gunicorn 的 pid..
--reload
选项查找对源代码而非配置的更改。而且 --reload
无论如何都不应该在生产中使用。
我会:
1) 告诉 gunicorn 用 --pid /path/to/pid/file
写一个 pid 文件,然后用 salt 杀死 pid 然后重启。
2) 将 salt 添加到 运行 a pkill gunicorn
然后重新启动。
不要运行shell命令来管理服务,使用service
状态。
/path/to/nginx.conf:
file.managed:
# ...
/path/to/config.ini:
file.managed:
# ...
nginx:
service.running:
- enabled: true
- watch:
- file: /path/to/nginx.conf
django-app:
service.running:
- enabled: true
- reload: true
- watch:
- file: /path/to/config.ini
您可能需要自己为 gunicorn 创建服务定义。这是一个非常基本的 systemd 示例:
[Unit]
Description=My django app
After=network.target
[Service]
Type=notify
User=www-data
Group=www-data
WorkingDirectory=/path/to/source
ExecStart=/path/to/venv/bin/python gunicorn project.wsgi:application
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=mixed
[Install]
WantedBy=multi-user.target