#!/usr/local/bin/perl

################################################################################
#
# File:    run
# Date:    $Date: 2008-04-06 20:13:45 -0500 (Sun, 06 Apr 2008) $
# Version: $Revision: 119 $
#
# This is the default run wrapper program.  A run wrapper is responsible for
# executing a job and maintaining 
#
################################################################################

use strict;
use warnings;


my $family_name   = shift;
my $job_name      = shift;
my $job_file_name = shift;
my $log_dir       = shift;
my $script_dir    = shift;
my $pid_file      = shift;
my $success_file  = shift;
my $failure_file  = shift;


print "Running job $family_name $job_name with pid $$\n";
open (PID,  ">$pid_file") || die "Can't open PID file $pid_file";
print PID "pid: $$\n";
print PID "actual_start: ", time, "\n";
close PID;

my $script = "$script_dir/$job_file_name";

system("$script");

open (PID,  ">>$pid_file") || die "Can't open PID file $pid_file";
print PID "stop: ", time, "\n";

my $rc = $?;
my $status_file;
if ($rc) { 
    $status_file = $failure_file;
}
else { 
    $status_file = $success_file;
}

print PID "rc: $rc\n";
close PID;

# touch status file
open (S, ">$status_file") || die "can't open $status_file status file";
print S "$rc\n";
close S;

