01 12 / 2011
Handling SIGQUIT to gracefully shutdown Starman »
Implemented QUIT handler to gracefully shutdown Starman workers (and full graceful restart with Server::Starter) - one of the ugliest monkeypatch I’ve written in a few months.
HUPのリスタート処理がlinux環境で app.psgi 以外のファイルパスを使っていた場合にうまく動いていなかったのを直したのと同時に、Server::Starter対応の部分で、デフォルトでTERMを受け取ったらgraceful shutdownしないといけないのが、そこが実装されてなかったのに気づいた。というわけで、SIGQUITでgraceful shutdown するようにパッチを書いたので、start_server --signal-on-hup=QUIT -- starman --preload-app ... で graceful restart 可能になった。
しかし、Net::Server のシグナル処理は非常に拡張しづらいので、register_sig をlocalで上書きしてとかmonkey patchしまくり。かといって今更Net::Serverにパッチをあてるのもどうかという気もするし(2010年10月に0.99が出て以来更新されていない)
Permalink 25 notes
01 12 / 2011
Changing the HUP handling in Starman »
Starman is one of the most popular HTTP preforking servers for PSGI/Plack, and its handling of HUP signals to do graceful restarts has been broken for a couple of months in certain environments.
There are many reasons for the breakage, one of which is the change in our own Plack ecosystem on how to manage @ARGV and the other is how fragile and insane the way Net::Server tries to restore its original command line.
Today I finally could reproduce the issue on my linux environment, and confirmed that the behavior is broken, and concluded that the way it tries to shutdown the original process and re-exec the daemon cannot be made reliable in the current way Plack loader works.
After a few minutes of discussion at #plack IRC channel, I committed a new patch which basically changes the SIGHUP handling in a really simple way: it just sends HUP to all the children, which will result in restarting all the workers. And just that. No re-exec or anything.
By default, restarting the workers will reload your application changes, except the modules pre-loaded in the master worker with -M option.
If you use —preload-app option to preload the entire app in the master, however, sending HUP will just restart the worker without reloading the code, which might not be what you expect. If you want to both fully preload the app and also reload the code with graceful restarts, use Kazuho Oku’s wonderful Server::Starter - Starman does support it.
Permalink 1 note