There is no standard way for PSGI applications to register a cleanup handler for each process, and Starman does not seem to implement anything that can be used directly. But you can decapitate Starman to run code when you exit the process.
Since Starman is based on Net :: Server :: PreFork and does not use child_finish_hook () itself, you can simply override this Net :: Server :: PreFork hook by inserting it into your .psgi file:
sub Starman::Server::child_finish_hook { $pub->close(); $ctx->term(); }
Using the END block to clean up (or only depending on the global destructor) may be somehow prevented by the internal use of ZMQ threads, and I think it would be wiser to leave signal processing in the Net :: Server infrastructure.
source share