savelogs.in 3.64 KB
Newer Older
1
#!/usr/bin/perl -wT
Leigh Stoller's avatar
Leigh Stoller committed
2
#
3
# Copyright (c) 2000-2002, 2004, 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/>.
# 
# }}}
Leigh Stoller's avatar
Leigh Stoller committed
23
#
Leigh Stoller's avatar
Leigh Stoller committed
24
use English;
25 26 27 28 29 30 31 32 33 34 35 36

# Save the tiplogs from an experiment

sub usage {
	print "Usage: $0 pid eid\n";
	exit(-1);
}

#
# Configure variables
#
my $TB          = "@prefix@";
37 38
my $CONTROL	= "@USERNODE@";
my $sshtb	= "$TB/bin/sshtb";
39 40 41 42 43 44 45

#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;
46 47
use Experiment;
use User;
48

49 50 51
# Locals
my $SAVEUID = $UID;

52 53 54 55 56
#
# Turn off line buffering on output
#
$| = 1;

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#
# We don't want to run this script unless its the real version.
#
if ($EUID != 0) {
    die("*** $0:\n".
        "    Must be root! Maybe its a development version?\n");
}

#
# Please run as yourself
# 
if ($UID == 0) {
    die("*** $0:\n".
        "    Please do not run this script as root!\n");
}

73 74 75 76 77 78
#
# Untaint the path
# 
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:/usr/sbin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

79
if (@ARGV != 2) {
80
    usage();
81 82 83 84
}

my ($pid,$eid) = @ARGV;

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#
# Untaint args.
#
if ($pid =~ /^([-\w]+)$/) {
    $pid = $1;
}
else {
    die("*** Bad data in pid: $pid.\n");
}
if ($eid =~ /^([-\w]+)$/) {
    $eid = $1;
}
else {
    die("*** Bad data in eid: $eid.\n");
}
100 101 102 103 104
my $experiment = Experiment->Lookup($pid, $eid);
if (!defined($experiment)) {
    die("*** $0:\n".
	"    Could not lookup experiment object!\n");
}
105

106 107 108 109 110
#
# Verify user and get his DB uid and other info for later.
#
my $this_user = User->ThisUser();
if (! defined($this_user)) {
111 112
    die("*** $0:\n".
	"    You do not exist in the Emulab Database!\n");
113
}
114
my $user_uid   = $this_user->uid();
115

116 117 118 119 120
#
# Verify permission to muck with this experiment. This is to head off
# permission problems early; the nodes are indvidually checked later
# in the library.
#
121 122
if (!$this_user->IsAdmin() &&
    !$experiment->AccessCheck($this_user, TB_EXPT_MODIFY)) {
123 124
    die("*** $0:\n".
	"    You do not have permission to save log files in $pid/$eid!\n");
125 126
}

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
#
# Find the names of all physical nodes with tip lines. 
#
my $query_result =
    DBQueryFatal("select r.node_id,r.vname,t.server from reserved as r ".
		 "left join nodes as n on n.node_id=r.node_id ".
		 "left join node_types as nt on nt.type=n.type ".
		 "left join tiplines as t on t.node_id=r.node_id ".
		 "where r.pid='$pid' and r.eid='$eid' and ".
		 "      nt.isvirtnode=0 and nt.isremotenode=0 and ".
		 "      t.server is not null");

if ($query_result->numrows == 0) {
    print "No console lines found for experiment $eid in project $pid!\n";
    exit(0);
}
143

144
my $savedir = PROJROOT() . "/$pid/tiplogs/$eid";
145
my $cmdargs = "$TB/sbin/savelogs.proxy -u $user_uid -s $savedir ";
146

147 148
while (my ($nodeid, $vname) = $query_result->fetchrow_array()) {
    $cmdargs .= " $nodeid $vname";
149 150
}

151 152 153 154 155 156
#
# Now we call over to the ops node to deal with the rest of this. 
#
$EUID = $UID = 0;
system("$sshtb -host $CONTROL $cmdargs");
$EUID = $UID = $SAVEUID;
157

158 159 160 161
#
# Nothing else to do ... output from proxy went to stdout/stderr.
# 
exit($? >> 8);
162