diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-03-10 15:39:35 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-03-10 15:39:35 +0200 |
commit | fc57437fa0aa9a35823aa809dfe3268fa6a1ab22 (patch) | |
tree | 8847e9030ea9cc9cf7f01524050899c4cf432269 /lib/App/Beam.pm | |
parent | c2c72e539e88157f4676bbb185c56e46a1b6d6b4 (diff) | |
download | beam-fc57437fa0aa9a35823aa809dfe3268fa6a1ab22.tar.gz beam-fc57437fa0aa9a35823aa809dfe3268fa6a1ab22.tar.bz2 |
Ensure consistent exit code; standardize verbosity levels
Diffstat (limited to 'lib/App/Beam.pm')
-rw-r--r-- | lib/App/Beam.pm | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/lib/App/Beam.pm b/lib/App/Beam.pm index 3bee8b9..550bfcf 100644 --- a/lib/App/Beam.pm +++ b/lib/App/Beam.pm @@ -9,8 +9,9 @@ use POSIX qw(strftime floor); require App::Beam::Config; our @ISA = qw(App::Beam::Config); - + use App::Beam::History; +use App::Beam::History::Entry qw(:state); my $default_config_file = '/etc/beam.conf'; @@ -255,8 +256,8 @@ sub format_name { my ($self, $name, $idx) = @_; my $rec = $self->{history}->top($idx); return undef unless defined $rec; - $name .= '-' - . $rec->cycle + $name .= '-' if $name ne ''; + $name .= $rec->cycle . '-' . $rec->round . '-' @@ -301,7 +302,7 @@ sub load_backends { } } split(/\s+/, $self->get('core.items'))) { my $pack = "App::Beam::Backend::" . ucfirst($be); - $self->debug(1, "loading $pack"); + $self->debug(2, "loading $pack"); my $obj = eval "use $pack; new $pack(\$self);"; if ($@) { $self->logger('crit', $@); @@ -323,14 +324,14 @@ sub begin { my $options = $self->get('logger.syslog.options') || 'pid'; openlog($tag, $options, $facility) or do { - croak "openlog failed"; + carp "openlog failed"; exit(EX_CONFIG); } } elsif (my $filename = $self->get('logger.file.name')) { my $mode = $self->get('logger.file.append') ? '>>' : '>'; open(STDERR, $mode, $filename) or do { - croak "can't open file $filename for logging"; + carp "can't open file $filename for logging"; exit(EX_CANTCREAT); }; } @@ -356,7 +357,22 @@ sub begin { exit(EX_CANTCREAT); } } - + +use constant { + EX_SUCCESS => 0, # Successful termination + EX_FAILURE => 1, # All operations failed + EX_PARTIAL => 2 # Some operations failed +}; + +sub update_status { + my ($self, $ctr) = @_; + unless ($ctr == STATE_SUCCESS || $ctr == STATE_FAILURE) { + carp "invalid state counter $ctr; assuming STATE_FAILURE"; + $ctr = STATE_FAILURE; + } + $self->{counter}[$ctr]++; +} + sub end { my $self = shift; $self->{history}->top->finish; @@ -365,6 +381,16 @@ sub end { if ($self->get('logger.channel') eq 'syslog') { closelog(); } + + if ($self->{counter}[STATE_SUCCESS] > 0) { + if ($self->{counter}[STATE_FAILURE] > 0) { + exit(EX_PARTIAL); + } else { + exit(EX_SUCCESS); + } + } else { + exit(EX_FAILURE); + } } sub run { |