| 1 | package Clustericious::Command::start; | ||||||||||||||
| 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::Log; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | use File::Path qw( mkpath ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use File::Basename qw( dirname ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use Clustericious::App; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 1 | ▶ | use Clustericious::Config; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use Mojo::Base 'Clustericious::Command'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use Text::ParseWords qw( shellwords ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 1 | ▶ | use Carp (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 1 | ▶ | use Env qw( @PERL5LIB ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | # ABSTRACT: Clustericious command to start a Clustericious application | ||||||||||||||
| 16 | 1 | our $VERSION = '1.29'; # VERSION | |||||||||||||
| 17 | |||||||||||||||
| 18 | |||||||||||||||
| 19 | 1 | has description => <<EOT; | |||||||||||||
| 20 | Start a daemon using the config file. | ||||||||||||||
| 21 | EOT | ||||||||||||||
| 22 | |||||||||||||||
| 23 | 1 | has usage => <<EOT; | |||||||||||||
| 24 | usage $0: start | ||||||||||||||
| 25 | Start a daemon using the start_mode in the config file. | ||||||||||||||
| 26 | See Clustericious::Config for the format of the config file. | ||||||||||||||
| 27 | See Clustericious::Command::Start for examples. | ||||||||||||||
| 28 | EOT | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 0 | ▶ | sub run { | ||||||||||||
|
Subroutine
run: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||
| 31 | 0 | my($self, @args) = @_; | |||||||||||||
| 32 | 0 | ▶ | exit 2 unless $self->app->sanity_check; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | 0 | my $app = $ENV{MOJO_APP}; | |||||||||||||
| 34 | 0 | my $conf = $self->app->config; | |||||||||||||
| 35 | |||||||||||||||
| 36 | 0 | eval "use $app;"; | |||||||||||||
| 37 | 0 | ▶ | die $@ if $@; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | |||||||||||||||
| 39 | 0 | $self->app->init_logging; | |||||||||||||
| 40 | |||||||||||||||
| 41 | 0 | for my $mode ($self->app->config->start_mode) | |||||||||||||
| 42 | { | ||||||||||||||
| 43 | 0 | INFO "Starting $mode"; | |||||||||||||
| 44 | 0 | my %conf = $conf->$mode; | |||||||||||||
| 45 | 0 | ▶ | if(my $autogen = delete $conf{autogen}) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | { | ||||||||||||||
| 47 | 0 | ▶ | $autogen = [ $autogen ] if ref $autogen eq 'HASH'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | 0 | for my $i (@$autogen) | |||||||||||||
| 49 | { | ||||||||||||||
| 50 | 0 | DEBUG "autowriting ".$i->{filename}; | |||||||||||||
| 51 | 0 | mkpath(dirname($i->{filename}), 0, 0700); | |||||||||||||
| 52 | 0 | ▶ | open my $fp, ">$i->{filename}" or LOGDIE "cannot write to $i->{filename} : $!"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 0 | print $fp $i->{content}; | |||||||||||||
| 54 | 0 | ▶ | close $fp or LOGDIE $!; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | } | ||||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | # env hash goes to the environment | ||||||||||||||
| 59 | 0 | ▶ | my $env = delete $conf{env} || {}; | ||||||||||||
|
Condition0%0/2
delete $conf{'env'} || {}
MC/DC0%0/1
delete $conf{'env'} || {}
delete $conf{'env'}
Truth table0%0/2
A
A= delete $conf{'env'}
| |||||||||||||||
| 60 | 0 | @ENV{ keys %$env } = values %$env; | |||||||||||||
| 61 | 0 | ▶ | if($env->{PERL5LIB}) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | { | ||||||||||||||
| 63 | # Do it now, in case we are not spawning a new process. | ||||||||||||||
| 64 | 0 | push @INC, @PERL5LIB; | |||||||||||||
| 65 | } | ||||||||||||||
| 66 | 0 | TRACE "Setting env vars : ".join ',', keys %$env; | |||||||||||||
| 67 | |||||||||||||||
| 68 | 0 | my @args; | |||||||||||||
| 69 | |||||||||||||||
| 70 | 0 | ▶ | if(my $args = delete $conf{args}) | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 71 | { | ||||||||||||||
| 72 | 0 | ▶ | @args = ref $args ne 'ARRAY' ? (shellwords $args) : @$args; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 73 | } | ||||||||||||||
| 74 | elsif(%conf) | ||||||||||||||
| 75 | { | ||||||||||||||
| 76 | 0 | die "arguments specified withouth 'args' option\n"; | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 0 | DEBUG "Sending args for $mode : @args"; | |||||||||||||
| 80 | 0 | $ENV{MOJO_COMMANDS_DONE} = 0; | |||||||||||||
| 81 | 0 | Clustericious::Commands->start($mode,@args); | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 1 | 1; | |||||||||||||
| 86 | |||||||||||||||
| 87 | __END__ | ||||||||||||||