endexp.php3 4.24 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5
6
# All rights reserved.
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
7
include("defs.php3");
8
include("showstuff.php3");
9

Leigh B. Stoller's avatar
Leigh B. Stoller committed
10
11
12
#
# Only known and logged in users can end experiments.
#
13
$uid = GETLOGIN();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
14
LOGGEDINORDIE($uid);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
15

Leigh B. Stoller's avatar
Leigh B. Stoller committed
16
17
18
#
# Must provide the EID!
# 
Leigh B. Stoller's avatar
Leigh B. Stoller committed
19
20
21
22
23
24
25
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
  USERERROR("The project ID was not provided!", 1);
}

if (!isset($eid) ||
    strcmp($eid, "") == 0) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
26
27
28
  USERERROR("The experiment ID was not provided!", 1);
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
29
30
$exp_eid = $eid;
$exp_pid = $pid;
31

32
33
34
35
36
37
# Canceled operation redirects back to showexp page. See below.
if ($canceled) {
    header("Location: showexp.php3?pid=$pid&eid=$eid");
    return;
}

38
#
39
# Standard Testbed Header, after checking for cancel above.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
40
#
41
42
43
44
45
46
47
48
49
PAGEHEADER("Terminate a Testbed Experiment");

#
# Check to make sure thats this is a valid PID/EID, while getting the
# experiment GID.
#
if (! TBExptGroup($exp_pid, $exp_eid, $exp_gid)) {
    USERERROR("The experiment $exp_eid is not a valid experiment ".
	      "in project $exp_pid.", 1);
50
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
51

52
53
54
55
56
57
$query_result =
    DBQueryFatal("select lockdown FROM experiments WHERE ".
		 "eid='$exp_eid' and pid='$exp_pid'");
$row       = mysql_fetch_array($query_result);
$lockdown  = $row["lockdown"];

58
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
59
# Verify permissions.
60
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
61
62
if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_DESTROY)) {
    USERERROR("You do not have permission to end experiment $exp_eid!", 1);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
63
64
}

65
66
67
68
echo "<font size=+2>Experiment <b>".
     "<a href='showproject.php3?pid=$exp_pid'>$exp_pid</a>/".
     "<a href='showexp.php3?pid=$exp_pid&eid=$exp_eid'>$exp_eid</a>".
     "</b></font>\n";
69
70
71
72
73
74
75

# A locked down experiment means just that!
if ($lockdown) {
    echo "<br><br>\n";
    USERERROR("Cannot proceed; the experiment is locked down!", 1);
}
   
76
77
78
#
# We run this twice. The first time we are checking for a confirmation
# by putting up a form. The next time through the confirmation will be
79
80
# set. Or, the user can hit the cancel button, in which case redirect the
# browser back up a level.
81
82
83
84
85
86
#
if (!$confirmed) {
    echo "<center><h2><br>
          Are you <b>REALLY</b>
          sure you want to terminate Experiment '$exp_eid?'
          </h2>\n";
87
88

    SHOWEXP($exp_pid, $exp_eid, 1);
89
    
Leigh B. Stoller's avatar
Leigh B. Stoller committed
90
    echo "<form action='endexp.php3?pid=$exp_pid&eid=$exp_eid' method=post>";
91
92
93
94
95
96
97
98
99
100
    echo "<input type=hidden name=exp_pideid value=\"$exp_pideid\">\n";
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
    echo "</form>\n";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
101
#
102
# We need the unix gid for the project for running the scripts below.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
103
# Note usage of default group in project.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
104
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
105
TBGroupUnixInfo($exp_pid, $exp_gid, $unix_gid, $unix_name);
106
107

#
108
109
110
111
112
# We run a wrapper script that does all the work of terminating the
# experiment. 
#
#   tbstopit <pid> <eid>
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
113
echo "<center><br>";
114
115
echo "<h2>Starting experiment termination. Please wait a moment ...
      </h2></center>";
116
117

flush();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
118
119

#
120
# Run the backend script.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
121
#
122
$retval = SUEXEC($uid, "$exp_pid,$unix_gid", "webendexp $exp_pid $exp_eid",
123
		 SUEXEC_ACTION_IGNORE);
124

125
126
127
128
#
# Fatal Error. Report to the user, even though there is not much he can
# do with the error. Also reports to tbops.
# 
129
if ($retval < 0) {
130
131
132
133
    SUEXECERROR(SUEXEC_ACTION_DIE);
    #
    # Never returns ...
    #
Leigh B. Stoller's avatar
Leigh B. Stoller committed
134
135
136
    die("");
}

137
#
138
139
# Exit status >0 means the operation could not proceed.
# Exit status =0 means the experiment is terminating in the background.
140
#
141
echo "<br>\n";
142
if ($retval) {
143
144
    echo "<h3>Experiment termination could not proceed</h3>";
    echo "<blockquote><pre>$suexec_output<pre></blockquote>";
145
146
}
else {
147
    echo "<h3>Your experiment is terminating!</h3><br>
148
149
          You will be notified via email when the experiment has been torn
	  down, and you can reuse the experiment name.
150
151
          This typically takes less than two minutes, depending on the
          number of nodes in the experiment.
152
153
          If you do not receive email notification within a reasonable amount
          of time, please contact $TBMAILADDR.\n";
154
155
156
157
158
159

    echo "<br><br>
          If you are the morbid type, you can watch the experiment die in
          <a target=_blank href=spewlogfile.php3?pid=$exp_pid&eid=$exp_eid>
          realtime</a>.\n";
    
160
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
161

162
163
164
165
#
# Standard Testbed Footer
# 
PAGEFOOTER();
Leigh B. Stoller's avatar
Leigh B. Stoller committed
166
?>