| 1 | package Clustericious::Command::hypnotoad; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Clustericious; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Clustericious::App; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Clustericious::Log; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Mojo::Server::Hypnotoad; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use base 'Clustericious::Command'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # ABSTRACT: Clustericious command to stat Hypnotoad | ||||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = '1.29'; # VERSION | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | __PACKAGE__->attr(description => "Start a hypnotad web server.\n"); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | __PACKAGE__->attr(usage => <<EOT); | |||||||||||||||||||||||||||
| 18 | Usage $0: hypnotoad | ||||||||||||||||||||||||||||
| 19 | No options are available. The 'hypnotoad' entry in the config file | ||||||||||||||||||||||||||||
| 20 | is used for configuration. | ||||||||||||||||||||||||||||
| 21 | EOT | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 0 | my($self, @args) = @_; | |||||||||||||||||||||||||||
| 25 | 0 | my $conf = $self->app->config->hypnotoad; | |||||||||||||||||||||||||||
| 26 | 0 | my $exe = $0; | |||||||||||||||||||||||||||
| 27 | 0 | DEBUG "Running hypnotoad : $exe"; | |||||||||||||||||||||||||||
| 28 | 0 | $ENV{HYPNOTOAD_EXE} = "$0"; | |||||||||||||||||||||||||||
| 29 | 0 | my $sentinel = '/no/such/file/because/these/are/deprecated'; | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ( $ENV{HYPNOTOAD_CONFIG} && $ENV{HYPNOTOAD_CONFIG} ne $sentinel ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ENV{"HYPNOTOAD_CONFIG"} and $ENV{"HYPNOTOAD_CONFIG"} ne $sentinel
MC/DC0%0/2
$ENV{"HYPNOTOAD_CONFIG"} and $ENV{"HYPNOTOAD_CONFIG"} ne $sentinel
$ENV{"HYPNOTOAD_CONFIG"}
$ENV{"HYPNOTOAD_CONFIG"} ne $sentinel
Truth table0%0/3
A and B
A= $ENV{"HYPNOTOAD_CONFIG"}B= $ENV{"HYPNOTOAD_CONFIG"} ne $sentinel
| |||||||||||||||||||||||||||||
| 31 | 0 | WARN "HYPNOTOAD_CONFIG value $ENV{HYPNOTOAD_CONFIG} will be ignored"; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | # During deprecation, this value must be defined but not pass the -r test | ||||||||||||||||||||||||||||
| 34 | # to avoid warnings. | ||||||||||||||||||||||||||||
| 35 | 0 | my $pid = fork(); | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | if (!defined($pid)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | LOGDIE "Unable to fork"; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | unless ($pid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | DEBUG "Child process $$"; | |||||||||||||||||||||||||||
| 42 | 0 | local $ENV{HYPNOTOAD_CONFIG} = $sentinel; | |||||||||||||||||||||||||||
| 43 | 0 | my $pid_file = $conf->{pid_file}; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (-e $pid_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | chomp (my $pid = Clustericious::_slurp_pid $pid_file); | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | if (!kill 0, $pid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | WARN "removing old pid file $pid_file"; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | unlink $pid_file or WARN "Could not remove $pid_file : $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | my $toad = Mojo::Server::Hypnotoad->new; | |||||||||||||||||||||||||||
| 52 | 0 | $ENV{CLUSTERICIOUS_COMMAND_NAME} = 'hypnotoad'; | |||||||||||||||||||||||||||
| 53 | 0 | $toad->run($exe); | |||||||||||||||||||||||||||
| 54 | 0 | WARN "hypnotoad exited"; | |||||||||||||||||||||||||||
| 55 | 0 | exit; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | # TODO: see if we can get away without | ||||||||||||||||||||||||||||
| 58 | # using this sleep... it would speed up | ||||||||||||||||||||||||||||
| 59 | # the test suite a lot. | ||||||||||||||||||||||||||||
| 60 | 0 | sleep 1; | |||||||||||||||||||||||||||
| 61 | 0 | return 1; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | 1; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||