#!/usr/bin/perl use strict; use warnings; use IPC::Open2; my $SCIRE_CONFIG_FILE = '../etc/scire.conf'; my %conf; my ($SERVER_STDOUT, $SERVER_STDIN); parse_command_line(); read_config(); # Build the connection command. # This will eventually be something like "ssh scire@${scireserver} /usr/bin/scireserver.pl" my $connection_command = "ssh "; if(defined($conf{port})) { $connection_command .= "-o Port=$conf{port} "; } $connection_command .= "$conf{user}\@$conf{host} $conf{server_script}"; if(-d ".svn") { # Overwrite $connection_command in the case of a dev environment for now $connection_command = "../server/scireserver.pl"; } if(! -d $conf{job_dir}) { print "WARNING! $conf{job_dir} does not exist...creating\n"; mkdir $conf{job_dir}, 0660; } run_main(); sub run_main { #ok folks so here's how this thang goes down. #1. Connect. #2. Register with the DB. (only it knows if you're allowed to be active) #3. Scan the jobs directory. If there are done/failed jobs, report them. Note jobs in running or queue. #4. Fetch the jobs list #5. ? create_connection(); run_test(); } sub run_test { for(('PING', 'FOO', 'QUIT')) { send_command($_); my $response = get_response(); print "Got: ${response}"; } } sub parse_command_line { # XXX: Anyone know how to use getopt? I've never bothered figuring it out :P while($#ARGV > -1) { my $foo = shift @ARGV; if($foo eq "-f") { $SCIRE_CONFIG_FILE = shift @ARGV; } else { print "Unrecognized command line option: ${foo}\n"; } } } sub send_command { my $cmd = shift; my @args = @_; my $tosend = "${cmd}"; for my $arg (@args) { if($arg =~ /^[0-9]+$/) { $tosend .= " ${arg}"; } else { $arg =~ s/"/\\"/g; $tosend .= " \"${arg}\""; } } print "Sending: ${tosend}\n"; print SERVER_STDIN "${tosend}\n"; } sub get_response { # XXX: Add some logic for multi-line responses here my $response = ; return $response; } sub create_connection { # XXX: We need to see what this function returns if the command returns non-zero my $pid = open2(*SERVER_STDOUT, *SERVER_STDIN, $connection_command); } sub read_config { open(FH, "< ${SCIRE_CONFIG_FILE}") or die("Couldn't open the config file ${SCIRE_CONFIG_FILE}: $!"); while () { chomp; next if /^\s*(?:#|$)/; my ($key,$val) = split /=/; $conf{lc($key)} = $val; } close(FH) or die("Couldn't close the config file ${SCIRE_CONFIG_FILE}: $!"); }