<commit_before>#! /usr/bin/perl -w

#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
use POSIX qw(setsid);

sub usage()
{
    print "Usage: pilot-wrapper\n";
    exit(1);
}
my $optlist = "";
my $PIDFILE = "/var/run/pilot-wrapper.pid";
my $LOGFILE = "/var/emulab/logs/pilot-wrapper.log";
my $childpid;

#
# Turn off line buffering on output
#
$| = 1;

# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }

# Change to the directory where the pilot's config file is.
chdir("/etc/emulab");

#
# Load the OS independent support library. It will load the OS dependent
# library and initialize itself. 
# 
use libsetup;
# use libtmcc;
use libtestbed;

#
# Must be root.
# 
if ($UID != 0) {
    die("*** $0:\n".
	"    Must be root to run this script!\n");
}

# Signal handler to initiate cleanup in parent and the children.
sub Pcleanup($)
{
    my ($signame) = @_;

    $SIG{TERM} = 'IGNORE';

    if (defined($childpid)) {
	system("kill $childpid");
	waitpid($childpid, 0);
    }
    unlink $PIDFILE;
    exit(0);
}

# Daemonize;
if (TBBackGround($LOGFILE)) {
    sleep(1);
    exit(0);
}

#
# Write our pid into the pid file so we can be killed later. 
#
system("echo '$PID' > $PIDFILE") == 0 or
    die("*** $0:\n".
	"    Could not create $PIDFILE!");

# Okay, cleanup function.
$SIG{TERM} = \&Pcleanup;

# Fully disconnect from bootup. 
setsid();

# Loop forever, restarting pilot if it ever dies.
while (1) {
    $childpid = fork();

    die("*** $0:\n".
	"    Could not fork!\n")
	if ($childpid < 0);

    if ($childpid == 0) {
	$retval = system("$BINDIR/brainstem-reset");
	if ($retval != 0) {
	    print "WARNING: brainstem reset failed ($retval)!!!\n";
	}

	sleep(1);

	exec("$BINDIR/garcia-pilot -d -l /var/emulab/logs/pilot.log");
	die("*** $0:\n".
	    "    Could not exec garcia-pilot!\n");
    }
    waitpid($childpid, 0);

    sleep(1);
}
exit(0);<commit_msg>Put brainstem-reset call after running pilot, running the reset before starting pilot seemed to cause problems.<commit_after>#! /usr/bin/perl -w

#
# EMULAB-COPYRIGHT
# Copyright (c) 2005 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
use POSIX qw(setsid);

sub usage()
{
    print "Usage: pilot-wrapper\n";
    exit(1);
}
my $optlist = "";
my $PIDFILE = "/var/run/pilot-wrapper.pid";
my $LOGFILE = "/var/emulab/logs/pilot-wrapper.log";
my $childpid;

#
# Turn off line buffering on output
#
$| = 1;

# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }

# Change to the directory where the pilot's config file is.
chdir("/etc/emulab");

#
# Load the OS independent support library. It will load the OS dependent
# library and initialize itself. 
# 
use libsetup;
# use libtmcc;
use libtestbed;

#
# Must be root.
# 
if ($UID != 0) {
    die("*** $0:\n".
	"    Must be root to run this script!\n");
}

# Signal handler to initiate cleanup in parent and the children.
sub Pcleanup($)
{
    my ($signame) = @_;

    $SIG{TERM} = 'IGNORE';

    if (defined($childpid)) {
	system("kill $childpid");
	waitpid($childpid, 0);
    }
    unlink $PIDFILE;
    exit(0);
}

# Daemonize;
if (TBBackGround($LOGFILE)) {
    sleep(1);
    exit(0);
}

#
# Write our pid into the pid file so we can be killed later. 
#
system("echo '$PID' > $PIDFILE") == 0 or
    die("*** $0:\n".
	"    Could not create $PIDFILE!");

# Okay, cleanup function.
$SIG{TERM} = \&Pcleanup;

# Fully disconnect from bootup. 
setsid();

# Loop forever, restarting pilot if it ever dies.
while (1) {
    $childpid = fork();

    die("*** $0:\n".
	"    Could not fork!\n")
	if ($childpid < 0);

    if ($childpid == 0) {
	sleep(1);

	exec("$BINDIR/garcia-pilot -d -l /var/emulab/logs/pilot.log");
	die("*** $0:\n".
	    "    Could not exec garcia-pilot!\n");
    }
    waitpid($childpid, 0);

    sleep(3);

    $retval = system("$BINDIR/brainstem-reset");
    if ($retval != 0) {
	print "WARNING: brainstem reset failed ($retval)!!!\n";
    }
    
    sleep(3);
}
exit(0);
{'fraction_non_alphanumeric': 0.17012048192771084, 'fraction_numerical': 0.011807228915662651, 'mean_word_length': 3.1802618328298085, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3497766', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1535, 'n_words': 461}