[英]How do you deploy a PSGI script in Apache without restarting?
I want to deploy a PSGI scripts that runs in Apache2 with Plack.我想用 Plack 部署一个在 Apache2 中运行的 PSGI 脚本。 Apache is configured with: Apache 配置有:
<Location "/mypath">
SetHandler perl-script
PerlResponseHandler Plack::Handler::Apache2
PerlSetVar psgi_app /path/to/my/script.psgi
</Location>
When I test the script with plackup, the --reload
parameter watches updates on the .psgi
file.当我使用 plackup 测试脚本时,--reload 参数会.psgi
--reload
上的更新。 In the production environment it is fine that Apache and Plack do not check and restart on each change for performance reasons, but how can I tell them explicitly to restart Plack::Handler::Apache2
and/or the PSGI script to deploy a new version?在生产环境中,出于性能原因,Apache 和 Plack 不会检查并重新启动每次更改,但我如何明确告诉他们重新启动Plack::Handler::Apache2
和/或 PSGI 脚本以部署新版本?
It looks like Plack regularly checks for some changes but I have no clue when.看起来 Plack 会定期检查一些变化,但我不知道什么时候。 Moreover it seems to create multiple instances, so I sometimes get different versions of script.psgi
when at /mypath
.此外,它似乎创建了多个实例,所以有时我在/mypath
时会得到不同版本的script.psgi
。 It would be helpful to manually flush perl response handler without having to restart Apache or to wait for an unknown amount of time.手动刷新 perl 响应处理程序会很有帮助,而无需重新启动 Apache 或等待未知的时间。
The short answer is you can't.简短的回答是你不能。 That's why we recommend you to use plackup (with -r) for quick development and use Apache only for deployment (production use).这就是为什么我们建议您使用 plackup(带 -r)进行快速开发,并将 Apache 仅用于部署(生产使用)。
The other option is have a development apache process, and set MaxRequestsPerChild to a really small value, so that you will get a fresh child spawned in a very short period of time.另一种选择是开发 apache 进程,并将 MaxRequestsPerChild 设置为非常小的值,这样您就可以在很短的时间内生成一个新的孩子。 I haven't tested this, and doing so will definitely impact the performance of your entire httpd, if you run the non-development application running on the same process (which is a bad idea in the first place anyway).我没有对此进行测试,如果您运行在同一进程上运行的非开发应用程序,这样做肯定会影响整个 httpd 的性能(无论如何这首先是个坏主意)。
You can move your application out of the appache process, eg您可以将您的应用程序移出 appache 进程,例如
FastCgiExternalServer /virtual/filename/fcgi -socket /path/to/my/socket
an run your programm with运行你的程序
plackup -s FCGI --listen /path/to/my/socket --nproc 10 /path/to/my/script.psgi
This way you can restart your application without restarting apache.这样您就可以在不重新启动 apache 的情况下重新启动应用程序。
if you save the pid of the main fcgi process (--pid $pid_file) you can easyly restart an load your new code.如果您保存主 fcgi 进程的 pid (--pid $pid_file),您可以轻松地重新启动加载新代码。
There is also a module avail to manage (start,stop, restart) all your fcgi pools: https://metacpan.org/pod/FCGI::Engine::Manager::Server::Plackup (not tested)还有一个模块可用于管理(启动、停止、重新启动)所有 fcgi 池: https://metacpan.org/pod/FCGI::Engine::Manager::Server::Plackup (未测试)
Apache2::Reload (untested) Apache2::重新加载(未经测试)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.