I have the following code. I want to call the $pub->close
method when the starman server receives the HUP signal.
- How do I know that the child process ends?
- Could I use an END {} block? I tried this and it seems to work when plackup restarts (after an edit). I tried this with starman. I sent the HUP signal, but the children aren't restarted.
- Should I install a signal handlers for HUP? How does that work?
I want to clean up before the child restarts, if I don't the child process will block.
This is the .psgi file that I use.
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
}