Cikl

 view release on metacpan or  search on metacpan

bin/cikl_crontool  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

# fix lib paths, some may be relative
BEGIN {
    require File::Spec;
    my @libs = (
        "lib",
        "local/lib",
    );
    my $bin_path;

    for my $lib (@libs) {
        unless ( File::Spec->file_name_is_absolute($lib) ) {
            unless ($bin_path) {
                if ( File::Spec->file_name_is_absolute(__FILE__) ) {
                    $bin_path = ( File::Spec->splitpath(__FILE__) )[1];
                }
                else {
                    require FindBin;
                    no warnings "once";
                    $bin_path = $FindBin::Bin;
                }
            }
            $lib = File::Spec->catfile( $bin_path, File::Spec->updir, $lib );
        }
        unshift @INC, $lib;
    }

}

use Config::Simple;
use Getopt::Std;
use Data::Dumper;
use MIME::Lite;
use Try::Tiny;

my %opts;
getopts('b:A:NadC:c:p:c:hL:S:F:v:',\%opts);
my $period          = $opts{'p'} || 'daily';
my $throttle        = $opts{'T'} || 'medium';
my $cron_tool       = $opts{'b'} || 'cikl_smrt';
my $config          = $opts{'C'} || $ENV{'HOME'}.'/.cikl';
my $debug           = $opts{'d'};
my $debug_level     = $opts{'v'};
my $mutex           = $opts{'L'} || '/tmp/cikl_crontool.lock.'.$period;
my $start_at        = $opts{'S'};
my $dir             = $opts{'F'} || '/opt/cikl';
my $admin           = $opts{'A'} || 'root';
my $fail_closed     = $opts{'N'} || 0;

if(! -e $cron_tool){
    if(-e './bin/'.$cron_tool){
       $cron_tool = './bin/'.$cron_tool;
    } elsif(-e $dir.'/bin/'.$cron_tool){
        $cron_tool = $dir.'/bin/'.$cron_tool;
    } else {
        die 'unable to find '.$cron_tool;
    }
}
sub cleanup {
    my $msg = shift;
    if($msg){
        print $msg."\n";
    } else {
        print "\n\nCaught Interrupt (^C), Aborting\n";
    }
    remove_lock();
    exit(1);
}

my @files;
## TODO make this a var
my $feedsdir = (-e './rules/etc') ? './rules/etc' : $dir.'/etc';
unless($opts{'c'}){
    # TODO -- this is a confusing error, it means you installed Cikl to a non-std location and aren't using the -F option
    # we're getting rid of cikl_crontool in the future, so this is the shim for now.
    opendir(F,$feedsdir) || die('the directory: '.$feedsdir.' doesn\'t exist.. check your -F option if you installed Cikl somewhere else'."\n".$!);
    @files = sort { $a cmp $b } grep(/.cfg$/,readdir(F));
    close(F);
} else {
    push(@files,$opts{'c'});
}

my @crons;
foreach(@files){
    my $cc_name = $feedsdir.'/'.$_;
    my $err;
    my $cc;
    try {
        $cc = Config::Simple->new($cc_name);
    } catch {
        $err = shift;
    };
    if($err){
        my @errmsg;



( run in 1.913 second using v1.01-cache-2.11-cpan-d8267643d1d )