有没有办法使用 Fabric 将 django 站点置于维护模式?
我目前正在使用 MaintenanceModeMiddleware 将我的网站置于维护模式,但它需要您在远程服务器上的 settings.py 文件中进行更改。我想使用 Fabric 远程将站点置于维护模式。有办法实现这一点吗?或者有更好的方法来做到这一点吗?谢谢。
[更新]
感谢大家的反馈,最后这就是我所做的,它对我来说非常有用,http://garthhumphreys.com/2011/06/11/painless-django-maintenance -mode-with-fabric/ - 我确实喜欢取消注释行的想法,但是根据我的设置,如果我要在生产服务器上执行此操作,它将被覆盖一旦我推出了新版本,所以最终从服务器级别而不是 django 级别将站点置于维护模式会更好,并且确实更容易和灵活,至少对我来说:)
I'm currently using MaintenanceModeMiddleware to put my site into maintenance mode, but it requires you make the change in the settings.py file on the remote server. I would like to use fabric to remotely put the site into maintenance mode. Is there a way to achieve this? Or is there a better method for doing this? Thanks.
[UPDATE]
Thanks for the feedback everyone in the end this is what I did and it works great for me, http://garthhumphreys.com/2011/06/11/painless-django-maintenance-mode-with-fabric/ - I do like the idea of uncomment lines but with my setup if I were to do that on the production server it would be overwritten once I pushed the new version out, so in the end putting the site into maintenance mode from the server level and not the django level works a lot better and is truly easier and flexible, for me at least :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Fabric 确实有一些命令可以帮助您注释或取消注释
fabric.contrib.files
中给定文件中的行。请参阅此处的文档: http://docs.fabfile.org /en/1.0.1/api/contrib/files.html就我个人而言,我更喜欢在前端代理而不是 Django 中间件中处理这个问题。我会看一下这个问题 Show a custom 503 page if上游已关闭,这将 Nginx 配置为在上游关闭时使用自定义页面。
Fabric does have commands to help you comment or uncomment lines in a given file in
fabric.contrib.files
. See the docs here: http://docs.fabfile.org/en/1.0.1/api/contrib/files.htmlPersonally I prefer to handle this at the front-end proxy rather than in a Django middleware. I would take a look at this question Show a custom 503 page if upstream is down which configures Nginx to use a custom page when the upstream is down.
我的解决方案:
这是 Apache 配置文件的相关部分:
然后是结构脚本的相关部分:
这工作得很好,尽管它确实依赖于 Django 在维护模式期间处理请求;如果只提供一个静态文件就好了。
My solution:
Here's the relevant section of the Apache config file:
Then the relevant parts of the fabric script:
This works well, though it does depend on Django handling requests during maintenance mode; it would be nice to just serve a static file.
有一个 django-maintenancemode 的分支,允许通过设置来打开/关闭维护模式数据库中的值。例如,您可以通过这种方式创建一个简单的管理命令来切换维护模式并通过结构调用它。我认为它比使用 mod_rewrite 更灵活。
There is a fork of django-maintenancemode that allows to turn the maintenance mode on/off by setting a value in database. This way you can, for example, create a simple management command to toggle the maintenance mode and call it via fabric. I think it's more flexible than using mod_rewrite.