Supervisor/Monitor.pm untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 51 CC 5 SCAR 29.7
CC
5
Cov
0%
load
30.0
init
2.0
BEGIN
2.0
CRAP 19.5
1 package XAS::Supervisor::Monitor;
2  
3 our $VERSION = '0.01';
4  
5 use XAS::Lib::Process;
6  
7 use XAS::Class
8 debug => 0,
9 version => $VERSION,
10 base => 'Badger::Prototype XAS::Base',
11 mixin => 'XAS::Lib::Mixins::Configs',
12 utils => 'trim :env :validation',
13 constants => 'TRUE FALSE',
14 accessors => 'cfg',
15 filesystem => 'Dir',
16 ;
17  
18 # ----------------------------------------------------------------------
19 # Public Methods
20 # ----------------------------------------------------------------------
21  
22 sub load {
23 my $self = shift;
24  
25 $self = $self->prototype() unless ref $self;
26  
27 my ($service) = validate_params(\@_, [1]);
28
29 my $processes = {};
30 my @sections = $self->cfg->Sections();
31  
32 foreach my $section (@sections) {
33  
34 next if ($section !~ /^program:/);
35  
36 my $env = {};
37 my ($alias) = $section =~ /^program:(.*)/;
38  
39 $alias = trim($alias);
40  
41 if (my $e = $self->cfg->val($section, 'environment', undef)) {
42  
43 $env = env_parse($e);
44  
45 }
46  
47 my $process = XAS::Lib::Process->new(
48 -alias => $alias,
49 -auto_start => $self->cfg->val($section, 'auto-start', TRUE),
50 -auto_restart => $self->cfg->val($section, 'auto-restart', TRUE),
51 -command => $self->cfg->val($section, 'command'),
52 -directory => Dir($self->cfg->val($section, 'directory', "/")),
53 -environment => $env,
54 -exit_codes => $self->cfg->val($section, 'exit-codes', '0,1'),
55 -exit_retries => $self->cfg->val($section, 'exit-retires', 5),
56 -group => $self->cfg->val($section, 'group', 'xas'),
57 -priority => $self->cfg->val($section, 'priority', 0),
58 -pty => 1,
59 -umask => $self->cfg->val($section, 'umask', '0022'),
60 -user => $self->cfg->val($section, 'user', 'xas'),
61 -redirect => $self->cfg->val($section, 'redirect', FALSE),
62 -output_handler => sub {
63 my $output = shift;
64 $output = trim($output);
65 if (my ($level, $line) = $output =~/\s+(\w+)\s+-\s+(.*)/ ) {
66 $level = lc(trim($level));
67 $line = trim($line);
68 $self->log->$level(sprintf('%s: %s', $alias, $line));
69 } else {
70 $self->log->info(sprintf('%s: -> %s', $alias, $output));
71 }
72 }
73 );
74  
75 $processes->{$alias} = $process;
76 $service->register($alias);
77  
78 }
79  
80 return $processes;
81  
82 }
83  
84 # ----------------------------------------------------------------------
85 # Private Methods
86 # ----------------------------------------------------------------------
87  
88 sub init {
89 my $class = shift;
90  
91 my $self = $class->SUPER::init(@_);
92  
93 $self->load_config();
94  
95 return $self;
96  
97 }
98  
99 1;
100  
101 __END__