Created
June 10, 2013 10:27
-
-
Save brianmed/5747787 to your computer and use it in GitHub Desktop.
Methodology for starting and stopping worker processes when hypnotoad stops and starts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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