ZMQ block when Starman gets HUP

I have the following code. I want to call the $pub->close method when the starman server receives a HUP signal.

  • How do I know if a child process will end?
  • Is it possible to use the END block {}? I tried this and it seems to work when plackup restarts (after editing). I tried this with style. I sent a HUP signal, but the children do not restart.
  • Should I install signal handlers for HUP? How it works?

I want to clear before restarting the child, if I do not block the child process.

This is the .psgi file I'm using.

 use ZMQ; use ZMQ::Constants ':all'; use Plack::Builder; our $ctx = ZMQ::Context->new(1); my $pub = $ctx->socket(ZMQ_PUB); $pub->bind('tcp://127.0.0.1:5998'); # I want to close the socket and terminate the context # when the server is restarted with kill -HUP pid # It seems the children won't restart because the sockets isn't closed. # The next two lines should be called before the child process ends. # $pub->close; # $ctx->term; builder { $app } 
+4
source share
1 answer

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.

+2
source

All Articles