eventsys_start.in 3.33 KB
Newer Older
1 2
#!/usr/bin/perl -wT
#
3
# Copyright (c) 2000-2007 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23
#
24
use strict;
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
use English;

#
# Start event schedulers for all swapped-in experiments.
# Run whenever the boss node is rebooted.
#

#
# Configure variables
#
my $TB		= "@prefix@";
my $TBOPS       = "@TBOPSEMAIL@";
my $BOSSADDR	= "@BOSSNODE@";
my $EVENTSYS    = @EVENTSYS@;
my $TESTMODE    = @TESTMODE@;

my $evcontrol	= "$TB/bin/eventsys_control";

#
# Only root can do this.
#
if ($UID) {
    die("*** $0:\n".
	"    You do not have permission to control the event system!\n");
}

#
# The event system is currently optional.
#
if (! $EVENTSYS) {
    exit(0);
}

#
# Do nothing when testing.
#
if ($TESTMODE) {
    print "Testing run - no event system.\n";
    exit(0);
}

#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;
72 73 74
use Experiment;

sub failed($$);
75 76 77 78 79 80 81 82 83 84 85

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

# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

#
86
# Find all the active experiments.
87
#
88
my @experiments = Experiment->AllActive();
89

90 91 92 93 94 95
foreach my $experiment (@experiments) {
    my $pid     = $experiment->pid();
    my $eid     = $experiment->eid();
    my $swapper = $experiment->GetSwapper();
    my $project = $experiment->GetProject();
    my $group   = $experiment->GetGroup();
96

97 98 99 100 101 102 103
    failed($experiment, "Could not load swapper object")
	if (!defined($swapper));
    failed($experiment, "Could not load project object")
	if (!defined($project));
    failed($experiment, "Could not load group object")
	if (!defined($group));
    
104 105 106
    #
    # Ignore "special" experiments
    #
107 108
    next
	if ($pid eq TB_OPSPID);
109

110 111 112 113
    my $unix_uid  = $swapper->unix_uid();
    my $unix_pgid = $project->unix_gid();
    my $unix_egid = $group->unix_gid();
    
114
    #
115 116 117 118
    # Set uid/gid to that of the user.  We need to be in both the
    # project's unix group and the experiments's unix group in order
    # for the scheduler to write its logfile (in eventsys_control).
    #
119 120
    # Set some environment too.
    #
121 122
    $GID = $unix_pgid;
    $EGID = "$unix_pgid $unix_pgid $unix_egid";
123
    $EUID = $UID = $unix_uid;
124
    $ENV{'USER'} = $swapper->uid();
125

126
    print "Starting event scheduler for $experiment ...\n";
127
    system("$evcontrol start $pid,$eid");
128
    if ($?) {
129 130 131
	failed($experiment, "$evcontrol failed, status=$?");
    }
    else {
132 133 134 135 136
	print "Started event scheduler for $pid/$eid\n";
    }
    # set uid back to root
    $EUID = $UID = 0;
}
137
exit(0);
138

139
sub failed($$)
140
{
141
    my ($experiment, $msg) = @_;
142 143

    warn("$msg");
144
    warn("WARNING: did not start event scheduler for $experiment");
145
}