#this perl program ensures the schedulereader is always running
#it should be run on the cron where the schedulereader should be run
#i would recommend setting it to run once every 5 minutes

use strict;
use warnings;


my $line;

my $bool;

my $PS;

my $CP = "";

#the -X argument increases the heap size...for some reason this program burns memory
#my $java_command = 'java -Xmx128m FileChecker /home/thmsoc/software_dev/filetracker/trackerconfig/filetracker.cfg';

my $java_command = 'java -Xmx128m FileChecker';

my $arg_list = '/home/thmsoc/software_dev/filetracker/trackerconfig/filetracker.cfg';

my $command_line = "$java_command $arg_list";

my $root_dir = "/home/thmsoc/software_dev";

my $java_classpath = "$root_dir/filetracker/filechecker/:/usr/local/pkg/mysql-connector-java-3.1.12/mysql-connector-java-3.1.12-bin.jar:/usr/local/pkg/j2sdk/lib/tools.jar:$root_dir/javautil:$root_dir/filetracker/satdata/:$root_dir/classlib/commons-net-1.4.1/commons-net-1.4.1.jar:$root_dir/classlib/jakarta-oro-2.0.8/jakarta-oro-2.0.8.jar";

#set classpath
#$CP = $ENV{'CLASSPATH'};

#if($CP !~ m/$java_classpath/)
#{
    #print "setting classpath\n";
    
    $ENV{'CLASSPATH'} = "$java_classpath";

    $CP = $ENV{'CLASSPATH'};

    #print "$CP\n";

#}
#else
#{
    #print "classpath already set\n";
#}

$bool = 0;

#print("begin\n");

open(PS,"/bin/ps -ef |");

while($line = <PS>)
{
    if($line =~ m/$java_command/)
    {
	$bool = 1;
    }
}

if($bool == 0)
{

    #print("failed to find schedulechecker restarting\n");

    #the process being called won't actually terminate until the 
    #schedulereader finishes so it forks the process and terminates the 
    #parent, so parent process returns to command line
    fork and exit;

    `$command_line &`;
}
else
{
    #print("found schedulechecker taking no action\n");
}

   
