Plack::Middleware::Restart: Zero‑downtime migration on Starman vs. Cherokee
0 reputation · 22 Dec 2022, 15:15 UTC
0 reputation · 22 Dec 2022, 15:15 UTC
The goal is to upgrade a small PSGI web application without dropping any active connections. Plack::Middleware::Restart achieves this by spawning a child process, keeping the listening socket open, and swapping parent and child. However, the middleware’s behavior depends on the underlying PSGI server’s graceful‑shutdown support.
Starman natively supports graceful shutdown, allowing the middleware to maintain connections during restart. Cherokee, on the other hand, requires explicit configuration to keep sockets open; otherwise, active connections are terminated immediately, defeating the zero‑downtime objective.
Additionally, the middleware relies on Perl 5.10+ for lexical signal handling and Plack 1.4+ for socket transfer APIs. Older servers or versions may lack the necessary hooks, leading to unpredictable behavior.
Unresolved decisions and questions:
Starman natively supports graceful shutdown, so Plack::Middleware::Restart swaps the parent and child while keeping the listening socket open. Cherokee, by default, closes sockets on a hard restart; you must enable graceful‑shutdown in its config and use a reload command.
In /etc/cherokee/cherokee.conf (or via the web‑admin GUI) set GracefulShutdown On for the listener you wish to preserve. Then issue cherokee-admin --reload (or cherokee-admin --restart --graceful) instead of killing the process. This keeps the socket bound while the old worker exits.
The middleware only swaps processes; it does not serialise your application’s globals. If your app relies on in‑memory data you have three practical options:
fork so it inherits the parent’s memory (works if the state is immutable or rebuilt on startup).SIGUSR1 and re‑initialise the state before forking.plackup --middleware Plack::Middleware::Restart app.psgi and watch the parent exit only after the child signals readiness.lsof -i :port to confirm the socket remains bound during the swap.GracefulShutdown and run cherokee-admin --reload. Verify the socket stays open with netstat -an | grep LISTEN.Which version of Cherokee are you running? Graceful shutdown support was added in 1.1.0; older releases will ignore the GracefulShutdown flag.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.