Skip to content

Instantly share code, notes, and snippets.

@brianmed
Created June 10, 2013 10:27
Show Gist options
  • Save brianmed/5747787 to your computer and use it in GitHub Desktop.
Save brianmed/5747787 to your computer and use it in GitHub Desktop.
Methodology for starting and stopping worker processes when hypnotoad stops and starts.
use strict;
use warnings;
# $DB::deep = 500;
use FindBin;
BEGIN { unshift @INC, "$FindBin::Bin/../lib" }
# $DB::single = 1;
InfoServant::Start->start_app('InfoServant');
package InfoServant::Start;
use Mojo::Base 'Mojolicious::Commands';
sub start_app {
my $self = shift;
return InfoServant::Server->new->build_app(shift)->start(@_);
}
package InfoServant::Server;
use Mojo::Base 'Mojo::Server';
use Mojo::Util;
use FindBin;
sub DESTROY {
my $stop = $ENV{HYPNOTOAD_STOP} // 0;
if ($stop) {
if (-f "/tmp/feeder.pl.pid") {
my $pid = Mojo::Util::slurp("/tmp/feeder.pl.pid");
kill('KILL', $pid);
}
}
else {
system("$^X $FindBin::Bin/../../../bin/feeder.pl &");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment