Permalink
Browse files

Not needed here

  • Loading branch information...
1 parent d678d38 commit 03323774ffcaa554ad8c32bd25a457610b14b47b @pfischermx committed Jul 31, 2012
Showing with 0 additions and 297 deletions.
  1. +0 −121 bin/foca
  2. +0 −108 bin/foca-fanticide
  3. +0 −47 bin/foca-server
  4. +0 −21 bin/testclient.pl
View
121 bin/foca
@@ -1,121 +0,0 @@
-#!/usr/local/bin/perl
-#
-# foca
-#
-# Author(s): Pablo Fischer (pfs@yahoo-inc.com)
-# Created: 06/19/2012 09:16:07 PM UTC 09:16:07 PM
-
-use strict;
-use warnings;
-use Data::Dumper;
-use Digest::MD5 qw(md5_hex);
-use FindBin;
-use Ir;
-use Seco::Getopt;
-use YAML::Syck;
-use lib "$FindBin::RealBin/../lib/";
-use Yahoo::UNI::SE::Foca::Client;
-
-# Take a guess where is the config file.
-my $default_cf = '/home/y/conf/foca/client.yaml';
-$default_cf = "$FindBin::RealBin/../conf/foca/client.yaml" unless (-f $default_cf);
-
-my $opt = Seco::Getopt->new(
- options => {
- 'c|config=s' => 'Path to foca client config',
- 'r|range=s' => 'Range of hosts to use',
- 'p|port=i' => 'Alternative HTTP port to use',
- 'y|yca-role=s' => 'Alternative YCA role to use',
- 'm|maxflight=i' => 'Max number of hosts to connect at once',
- 't|timeout=s' => 'Global timeout (secs) for each host',
- 'connect-timeout=i' => 'Connection timeout (secs) for each host',
- 'g|only-good' => 'Only show output of successful hosts',
- 'a|aggregate' => 'Show aggregated data (SLOW!)',
- 's|summary' => 'Show summary of good/bad hosts',
- 'debug' => 'Be more verbose',
- },
- default => {
- 'm' => 15,
- 't' => 60,
- 'c' => $default_cf,
- 'connect-timeout' => 5,
- },
- required => [
- 'r',
- ],
- description => "Foca client");
-
-my $config = $opt->get('c');
-my $range = $opt->get('r');
-my $debug = $opt->get('debug') || 0;
-my $maxflight = $opt->get('m');
-my $timeout = $opt->get('t');
-my $connect_timeout = $opt->get('connect-timeout');
-my $only_good = $opt->get('g');
-my $aggregate = $opt->get('a');
-my $summary = $opt->get('s');
-my $settings = LoadFile($config) if (-f $config);
-
-# Ok, lets take a look
-my $port = $opt->get('p') || $settings->{'port'} || undef;
-my $yca_role = $opt->get('y') || $settings->{'yca_role'} || undef;
-
-$opt->usage("No --port was given or found in config") unless $port;
-$opt->usage("No --yca-role was given or found in config") unless $yca_role;
-
-my $client = Yahoo::UNI::SE::Foca::Client->new(
- maxflight => $maxflight,
- timeout => $timeout,
- connect_timeout => $connect_timeout,
- port => $port,
- yca_role => $yca_role,
- debug => $debug);
-
-my $command = shift @ARGV;
-
-$opt->usage('Please provide a command (with its args if they are needed)') unless
- $command;
-
-my $aggdata = {};
-my (@good, @bad);
-my $iterator = $client->run($range, $command, {
- on_host => \&parse_host});
-
-if ($aggregate) {
- while(my($k, $v) = each %{$aggdata}) {
- my $range = Ir::compress_range($v->{'hosts'});
- print "$range: $v->{'output'}\n";
- }
-}
-
-if ($summary) {
- my ($total_good, $total_bad) = (scalar @good, scalar @bad);
- my $range_good = @good ? Ir::compress_range(\@good) : '';
- my $range_bad = @bad ? Ir::compress_range(\@bad) : '';
-
- print "Failed ($total_bad) $range_bad\n";
- print "Succeeded ($total_good) $range_good\n";
-}
-
-sub parse_host {
- my ($host) = @_;
- my $output = '';
- my $show = 1;
- if ($host->{'ok'}) {
- $output = "$host->{'output'}";
- push(@good, $host->{'hostname'}) if $summary;
- } else {
- $output = "ERROR: $host->{'output'}";
- push(@bad, $host->{'hostname'}) if $summary;
- }
- if ($aggregate) {
- my $md5 = md5_hex($output);
- $aggdata->{$md5} = {
- 'output' => $output} unless $aggdata->{$md5};
- push(@{$aggdata->{$md5}->{'hosts'}}, $host->{'hostname'});
- } else {
- return if (!$host->{'ok'} and $only_good);
- print "$host->{'hostname'}: $output\n";
- }
-}
-
View
@@ -1,108 +0,0 @@
-#!/usr/local/bin/perl
-#
-# foca-fanticide.pl
-#
-# Author(s): Pablo Fischer (pfs@yahoo-inc.com)
-# Created: 06/14/2012 04:19:17 PM UTC 04:19:17 PM
-
-use strict;
-use warnings;
-use Data::Dumper;
-use Fcntl;
-use FindBin;
-use Seco::Getopt;
-# Foca libs/modules
-use lib "$FindBin::RealBin/../lib/";
-use Yahoo::UNI::SE::Foca::Tools::Logger;
-# Yahoo libs/modules
-use MDBM_File;
-
-my $opt = Seco::Getopt->new(
- options => {
- 'pid-file=s' => 'MDBM file where the PID files are stored',
- 'run-once' => 'Only run one time',
- 'debug' => 'Run in debug mode',
- 'frequency=i' => 'Frequency (in seconds) to keep checking for dead PIDs',
- },
- required => [
- 'pid-file',
- ],
- default => {
- 'frequency' => 10,
- },
- description => "Foca - Kill imaginary or closed requests/pids");
-
-my $pid_file = $opt->get('pid-file');
-my $run_once = $opt->get('run-once') || 0;
-my $debug = $opt->get('debug') || 0;
-
-die "$pid_file does not exist" unless (-f $pid_file);
-
-init_logger();
-use_debug(1) if $debug;
-
-while(1) {
- # Collect connections that are still open
- my %established_ports = ();
- open(NETSTAT_H, 'netstat -tan |');
- while(<NETSTAT_H>) {
- chomp;
- next unless (/^tcp/);
- next unless (/ESTABLISHED\s+$/);
- my @columns = map {split ':'} split ' ';
- next unless (scalar @columns == 8);
- $established_ports{$columns[6]} = 1;
- }
- my %pid_connections;
- tie(
- %pid_connections,
- 'MDBM_File',
- $FindBin::RealBin . '/../var/foca/server_pids.mdbm',
- O_RDWR|O_CREAT|O_NONBLOCK,
- 0644,
- 0,
- 0);
-
- if (%pid_connections) {
- my $mdbm_obj = tied %pid_connections;
- while (my ($pid, $port) = each %pid_connections) {
- # Pid still running?
- if (-f '/proc/' . $pid . '/status') {
- log_debug("PID $pid is still running, checking if its connection " .
- "is still running");
- if (defined $established_ports{$port}) {
- log_debug("PID $pid is still running and with an active " .
- "connection, leaving it");
- } else {
- log_debug("PID $pid is still running but with NO active " .
- "connections, trying to kill it..");
- log_info("Killing $pid..");
- system("kill -9 $pid");
- # Give it a second..
- sleep(1);
- # Done-done with it?
- if (-f '/proc/' . $pid . '/status') {
- log_error("PID $pid failed to get killed... ");
- } else {
- log_info("PID $pid has been killed. Removing from MDBM file");
- $mdbm_obj->lock();
- delete $pid_connections{$pid};
- $mdbm_obj->unlock();
- $mdbm_obj->sync();
- }
- }
- } else {
- log_info("PID $pid is no longer running. Removing from MDBM file");
- $mdbm_obj->lock();
- delete $pid_connections{$pid};
- $mdbm_obj->unlock();
- $mdbm_obj->sync();
- }
- }
- } else {
- log_info("MDBM file seems to be empty or no pending connections/pids");
- }
- last;
-}
-
-
View
@@ -1,47 +0,0 @@
-#!/usr/local/bin/perl
-#
-# foca-server
-#
-# Author(s): Pablo Fischer (pfs@yahoo-inc.com)
-# Created: 06/13/2012 04:51:39 PM UTC 04:51:39 PM
-
-use strict;
-use warnings;
-use Data::Dumper;
-use FindBin;
-use Seco::Getopt;
-use lib "$FindBin::RealBin/../lib/";
-use App::Foca::Server;
-
-my $opt = Seco::Getopt->new(
- options => {
- 'p|port=i' => 'Where to listen',
- 't|timeout=s' => 'Global timeout (secs) for commands',
- 'c|command-file=s' => 'YAML file where allowed commands are',
- 'debug' => 'Be more verbose',
- },
- default => {
- 'p' => 6666,
- 't' => 60,
- },
- required => [
- 'c'
- ],
- description => "Foca server");
-
-my $port = $opt->get('p');
-my $timeout = $opt->get('t');
-my $commands = $opt->get('c');
-my $debug = $opt->get('debug');
-
-my $server = App::Foca::Server->new(
- port => $port,
- commands_file => $commands,
- commands_timeout => $timeout,
- debug => $debug);
-
-$server->run_server();
-
-
-
-
View
@@ -1,21 +0,0 @@
-#!/usr/local/bin/perl
-#
-# testclient.pl
-#
-# Author(s): Pablo Fischer (pfs@yahoo-inc.com)
-# Created: 06/26/2012 05:41:17 PM UTC 05:41:17 PM
-
-use strict;
-use warnings;
-use FindBin;
-use Ir;
-use Seco::Getopt;
-use YAML::Syck;
-use lib "$FindBin::RealBin/../lib/";
-use Yahoo::UNI::SE::Foca::Client;
-
-my $client = Yahoo::UNI::SE::Foca::Client->new;
-my @data = $client->run('localhost', 'uptime');
-use Data::Dumper;
-
-print Dumper(\@data);

0 comments on commit 0332377

Please sign in to comment.