All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit 0607b3b4 authored by Leigh B. Stoller's avatar Leigh B. Stoller

Change for templates. A new experiment run will cause the program

agent to exit. rc.progagent now loops, restarting the program agent,
but first getting new copies of the agent list and the environment
from tmcd.

Note that this conflicts slightly with the pa-wrapper used on plab
nodes, which also loops. I think we can just get rid of pa-wrapper
now, along with a slight change to rc.progagent. I'm gonna let Kirk
comment on this.

Need new images ...
parent 48e9952c
......@@ -1010,9 +1010,6 @@ startrun_callback(event_handle_t handle,
event_notification_t notification,
void *data)
{
char envdata[2*BUFSIZ], buf[BUFSIZ];
char *bp, *cp;
FILE *file;
struct proginfo *pinfo;
char event[TBDB_FLEN_EVEVENTTYPE];
......@@ -1038,33 +1035,10 @@ startrun_callback(event_handle_t handle,
stop_program(pinfo, NULL);
}
}
return;
}
event_notification_get_string(handle, notification,
"environment", envdata, sizeof(envdata));
warning("New Environment received!\n");
warning("%s\n", envdata);
bp = cp = envdata;
while ((bp = strsep(&cp, "\n")) != NULL) {
/* XXX Kind of a stupid way to eval any variables. */
if ((file = popenf("echo %s", "r", bp)) != NULL) {
if (fgets(buf, sizeof(buf), file) != NULL) {
char *idx;
if ((idx = strchr(buf, '\n')) != NULL)
*idx = '\0';
if ((idx = strchr(buf, '=')) != NULL) {
*idx = '\0';
setenv(strdup(buf), idx + 1, 1);
}
}
pclose(file);
file = NULL;
}
/*
* Wrapper will restart us.
*/
exit(45);
}
}
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2004, 2005 University of Utah and the Flux Group.
# Copyright (c) 2004, 2005, 2006 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
use POSIX ":sys_wait_h";
use POSIX qw(setsid);
sub usage()
{
......@@ -24,6 +26,7 @@ BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
# Script specific goo
my $LOGFILE = "$LOGDIR/progagent.debug";
my $WRAPLOG = "$LOGDIR/progwrap.debug";
my $PIDFILE = "/var/run/progagent.pid";
my $CONFIG = "$BOOTDIR/progagents";
my $PAGENT = "$BINDIR/program-agent";
......@@ -101,49 +104,87 @@ sub doboot()
my @agents = ();
my @userenv = ();
if (tmcc(TMCCCMD_PROGRAMS, undef, \@agents) < 0) {
fatal("Could not get progagent config from server!");
}
if (tmcc(TMCCCMD_USERENV, undef, \@userenv) < 0) {
fatal("Could not get user environment from server!");
}
unlink $CONFIG;
return
if (! @agents);
#
# Write the data to the file. The rc script will interpret it.
# Note that one of the lines (the first) indicates what user to
# run the agent as.
#
if (!open(RUN, ">$CONFIG")) {
fatal("Could not open $CONFIG: $!");
}
foreach my $line (@agents) {
print RUN "$line";
}
foreach my $line (@userenv) {
print RUN "ENV $line";
}
close(RUN);
#
# Need the pid/eid.
#
my ($pid, $eid, $vname) = check_nickname();
print "Starting Program Agent ...\n";
if (PLAB()) {
system("$PAWRAPPER $PAGENT -e $pid/$eid -s localhost -l $LOGFILE ".
"-i $PIDFILE -k " . TMEVENTKEY() . " -c $CONFIG");
} else {
system("$PAGENT -e $pid/$eid -s localhost -l $LOGFILE ".
"-i $PIDFILE -k " . TMEVENTKEY() . " -c $CONFIG &");
#
# Daemonize and let the boot continue. We have to disconnect and
# change our session id so that we do not killed off (nor the
# trafgen children) when boot script terminates. The downside is
# that we cannot report errors to the caller.
#
if (my $childpid = TBBackGround($WRAPLOG)) {
sleep(2);
# This catches most startup problems.
my $foo = waitpid($childpid, &WNOHANG);
if ($foo) {
my $status = $?;
unlink($PIDFILE);
system("cat $WRAPLOG")
if (-s $WRAPLOG);
fatal("Failed to program agent: $foo $status!");
}
exit(0);
}
# Fully disconnect from bootup.
setsid();
while (1) {
if (tmcc(TMCCCMD_PROGRAMS, undef, \@agents) < 0) {
fatal("Could not get progagent config from server!");
}
if (tmcc(TMCCCMD_USERENV, undef, \@userenv) < 0) {
fatal("Could not get user environment from server!");
}
unlink $CONFIG;
if ($?) {
fatal("Could not start program agent!");
#
# Write the data to the file. The rc script will interpret it.
# Note that one of the lines (the first) indicates what user to
# run the agent as.
#
if (!open(RUN, ">$CONFIG")) {
fatal("Could not open $CONFIG: $!");
}
foreach my $line (@agents) {
print RUN "$line";
}
foreach my $line (@userenv) {
print RUN "ENV $line";
}
close(RUN);
print "Starting Program Agent ...\n";
if (PLAB()) {
system("$PAWRAPPER $PAGENT -e $pid/$eid -s localhost -l $LOGFILE ".
"-d -i $PIDFILE -k " . TMEVENTKEY() . " -c $CONFIG");
# pa-wrapper already does what the loop above does.
exit($? >> 8);
}
else {
system("$PAGENT -e $pid/$eid -s localhost -l $LOGFILE ".
"-d -i $PIDFILE -k " . TMEVENTKEY() . " -c $CONFIG");
}
exit(0)
if (! $?);
# Like the magic exit code? This means the agent was told by boss
# to exit so that we can regen the config file and then restart.
# There is most certainly a better way to do this.
if ($? >> 8 != 45) {
fatal("program agent exited with non-zero status: $?");
}
#
# We want to restart, go around the loop again. Turn the cache off.
#
libtmcc::configtmcc("nocache", 1);
}
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment