App-nrun

 view release on metacpan or  search on metacpan

bin/nrun  view on Meta::CPAN

###
# initialize the queue object
sub queue_init {

    my $_self = shift;

    $options->{queue} = NRun::Queue->new();
    $options->{queue}->init (
        {
            objects => $options->{hosts},
        }
    );
}

###
# main
sub main {

    $options = NRun::Util::read_config_files (
        [
            "$FindBin::Bin/../etc/nrunrc",
            "/etc/nrunrc",
            NRun::Util::home() . "/.nrunrc" 
        ]
    );

    $options->{ppid} = $$;

    NRun::Signal::register('TERM', \&handler, [ \$options ]);
    NRun::Signal::register('INT',  \&handler, [ \$options ]);

    parse_commandline();

    sink_init();
    queue_init();

    $options->{pool} = NRun::Pool->new (
        {
            nmax    => $options->{parallel},
            timeout => $options->{timeout},

            sink => $options->{sink},
            queue => $options->{queue},

            callback => \&callback,
        }
    );

    $options->{sink}->process();
}

main();

__END__

=pod

=head1 NAME

nrun - run a single command or script on a multiple of target servers
synchronously.

=head1 SYNOPSIS

nrun -t HOST1[,HOST2,...] [--copy] [--log-directory]
[-p MAX] [--timeout SEC] [-v] [-m MODE] [-f FILTER] [-l LOGGER1[,LOGGER2...]] 
[-c CHECK1[,CHECK2]]  -- COMMAND

=head1 DESCRIPTION

nrun will run a single command or script on a multiple of target servers
synchronously.

the underlying remote access mechanism is exchangeable. as of now, ssh, nsh, rsh
and local execution modes are implemented.

=head1 OPTIONS

B<--check,-c CHECK1[,CHECK2]>    checks to be applied to each host (see CHECKS)

B<--copy,-c>                     copy command to target host before execution.

B<--filter,-f FILTER1>           output filter to be applied (see FILTER).

B<--logger,-l LOGGER1[,LOGGER2]> logger to be applied (see LOGGER).

B<--log-directory,-l DIR>        base directory for the log files.

B<--mode,-m MODE>                remote execution mode (see MODES).

B<--parallel,-p MAX>             number of parallel connections (defaults to 5).

B<--target,-t HOST1[,HOST2,...]> comma separated list of target hosts (see TARGETS).

B<--timeout SEC>                 timeout for each command execution (defaults to 60).

B<--version,-v>                  print the version string and exit.

=head1 CONFIGURATION

special configuration options for the different modes and additional all
commandline options can be given in a configuration file.

the following three places will be searched for configuration files (values in the last
configuration file will overwrite values in the first configuration file). indentation
does matter (YAML syntax).

- $FindBin::Bin/../etc/nrunrc

- /etc/nrunrc

- $HOME/.nrunrc

    ---
    # mode ssh options
    ssh_copy: >
        /usr/bin/scp
        -o User=root
        -o PreferredAuthentications=hostbased,publickey
        -o StrictHostKeyChecking=no
        -o UserKnownHostsFile=/dev/null
        -o LogLevel=FATAL
        SOURCE HOSTNAME:TARGET
    
    ssh_rcopy: >
        /usr/bin/scp
        -o User=root
        -o PreferredAuthentications=hostbased,publickey
        -o StrictHostKeyChecking=no
        -o UserKnownHostsFile=/dev/null
        -o LogLevel=FATAL
        HOSTNAME:SOURCE TARGET

bin/nrun  view on Meta::CPAN

'generic_copy'   - commandline for remote copying (SOURCE, TARGET, HOSTNAME will be replaced)

'generic_rcopy'  - commandline for reverse remote copying (SOURCE, TARGET, HOSTNAME will be replaced)

'generic_delete' - commandline for remote deletion (FILE, HOSTNAME will be replaced)

an example that resembles the mode ssh would look the following way:

    generic_copy: >
        /usr/bin/scp
        -o User=root
        -o PreferredAuthentications=hostbased,publickey
        -o StrictHostKeyChecking=no
        -o UserKnownHostsFile=/dev/null
        -o LogLevel=FATAL
        SOURCE HOSTNAME:TARGET
    
    generic_rcopy: >
        /usr/bin/scp
        -o User=root
        -o PreferredAuthentications=hostbased,publickey
        -o StrictHostKeyChecking=no
        -o UserKnownHostsFile=/dev/null
        -o LogLevel=FATAL
        HOSTNAME:SOURCE TARGET
    
    generic_exec: >
        /usr/bin/ssh
        -o User=root
        -o PreferredAuthentications=hostbased,publickey
        -o StrictHostKeyChecking=no
        -o UserKnownHostsFile=/dev/null
        -o LogLevel=FATAL
        HOSTNAME COMMAND ARGUMENTS
    
    generic_delete: >
        /usr/bin/ssh
        -o User=root
        -o PreferredAuthentications=hostbased,publickey
        -o StrictHostKeyChecking=no
        -o UserKnownHostsFile=/dev/null
        -o LogLevel=FATAL
        HOSTNAME rm -f "FILE"

=head1 FILTERS

a filter reads the raw output generated by the worker processes and prints this
output in a filter specific format. 

=head2 filter raw

this filter will just dump the output as it is provided by the worker process. no
formatting will be done.

format:

	HOSTNAME;[stdout|stderr];TSTAMP;PID;PID(CHILD);[debug|error|exit|output|end];"OUTPUT"

=head2 filter async

this filter dumps the worker process output unsynchronized in the following format. unsynchronised
means, that output lines from the different worker processes are printed at the same time they are
generated.

format:

	HOSTNAME: OUTPUT

=head2 filter sync

this filter dumps the worker process output synchronised in the following format. synchronized
means, that the complete output for a single hosts will be dumped at once when the worker proces
has finished execution.

format:

	HOSTNAME: OUTPUT

=head2 filter result

this filter will only print the exit codes for the worker processes.

format:

	HOSTNAME: exit code CODE

=head1 LOGGERS

a logger reads the raw output generated by the worker processes and logs this
output in a specific format. 

=head2 logger output

this logger creates a logfile in the logging directory called output.log which contains the same
data that the filter sync produces. 

=head2 logger result

this logger creates a logfile in the logging directory called result.log which contains the same
data that the filter result produces.

=head2 logger raw

this logger creates a logfile in the logging directory called raw.log which contains the same
data that the filter raw produces.

=head1 checks

a check does a specific check for each hostname. if the check fails, the hostname that failed will
be removed from the target list and an error message will be printed. multiple checks may be given
at the command line.

=head2 check ping

checks that the host is pingable.

=head2 check ns

checks that the hostname is resolvable to an ip address.

=head2 check rscd

checks that the rscd agent is alive.

=head1 TARGETS

a target name may be either a filename containing the target hosts, one per line,
an alias definition in the configuration file or simply a hostname.

if there is a conflict, for example an alias named identically as an existing
file, the alias will always overrule the filename and the filename will always



( run in 0.602 second using v1.01-cache-2.11-cpan-437f7b0c052 )