Daemon-Shutdown

 view release on metacpan or  search on metacpan

lib/Daemon/Shutdown/Monitor/smbstatus.pm  view on Meta::CPAN

package Daemon::Shutdown::Monitor::smbstatus;

use warnings;
use strict;
use Params::Validate qw/:all/;
use IPC::Run;
use YAML::Any;
use Log::Log4perl;

=head1 NAME

Daemon::Shutdown::Monitor::smbstatus - check for samba locks

=head1 SYNOPSIS

Monitor samba file locks

=head1 DESCRIPTION

Uses C<smbstatus> to look for locked files every "loop_sleep".  If no files are locked,
the flag "trigger_pending" is set.  If a further "trigger_time" seconds
pass and all disks are still in a spun down state, the trigger is sent back to the parent
process (return 1).

=head1 METHODS

=head2 new

=over 2

=item loop_sleep <Int>

How long to sleep between each test

Default: 60 (1 minute)

=item trigger_time <Int>

The time to wait after discovering that all disks are spun down before returning (trigger a shutdown).

Default: 3600 (1 hour)

=back

=head3 Example configuration
 
monitor:
  smbstatus:
    trigger_time: 1800
    loop_sleep: 360

=cut

sub new {
    my $class  = shift;
    my %params = @_;

    # Validate the config file
    %params = validate_with(
        params => \%params,
        spec   => {
            loop_sleep => {
                regex   => qr/^\d*$/,
                default => 60,
            },
            trigger_time => {
                regex   => qr/^\d*$/,
                default => 3600,
            },
        },
    );
    my $self = {};
    $self->{params} = \%params;

    $self->{trigger_pending} = 0;

    bless $self, $class;
    my $logger = Log::Log4perl->get_logger();
    $self->{logger} = $logger;
    $logger->debug( "Monitor smbstatus params:\n" . Dump( \%params ) );



( run in 0.535 second using v1.01-cache-2.11-cpan-39bf76dae61 )