Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emulab
emulab-devel
Commits
f2ef059a
Commit
f2ef059a
authored
Sep 26, 2001
by
Leigh B. Stoller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A bunch of little changes and cleanups.
parent
703e054a
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
136 additions
and
131 deletions
+136
-131
db/libdb.pm.in
db/libdb.pm.in
+14
-2
tbsetup/batch_daemon.in
tbsetup/batch_daemon.in
+2
-9
tbsetup/batchexp.in
tbsetup/batchexp.in
+2
-5
tbsetup/endexp.in
tbsetup/endexp.in
+1
-1
tbsetup/libtestbed.pm
tbsetup/libtestbed.pm
+12
-1
tbsetup/mkacct-ctrl.in
tbsetup/mkacct-ctrl.in
+1
-1
tbsetup/mkprojdir.in
tbsetup/mkprojdir.in
+0
-1
tbsetup/node_update.in
tbsetup/node_update.in
+21
-0
tbsetup/reload_daemon.in
tbsetup/reload_daemon.in
+2
-4
tbsetup/rmacct-ctrl.in
tbsetup/rmacct-ctrl.in
+2
-12
tbsetup/rmproj.in
tbsetup/rmproj.in
+40
-50
tbsetup/savevlans.in
tbsetup/savevlans.in
+30
-28
tbsetup/startexp.in
tbsetup/startexp.in
+9
-17
No files found.
db/libdb.pm.in
View file @
f2ef059a
...
...
@@ -26,11 +26,12 @@ use Exporter;
SetNodeBootStatus
OSFeatureSupported
IsShelved
NodeidToExp
UserDBInfo
DBQuery
DBQueryFatal
DBQueryWarn
DBWarn
DBFatal
DBQuoteSpecial
UNIX2DBUID
ExpState
SetExpState
ProjLeader
ExpNodes
ExpNodes
DBDateTime
);
#
Must
come
after
package
declaration
!
use
English
;
use
POSIX
qw
(
strftime
);
require
Mysql
;
#
Configure
variables
...
...
@@ -614,7 +615,7 @@ sub DBFatal($)
#
# Quote a string for DB insertion.
#
# usage: DBQuoteSpecial(char *string);
# usage:
char *
DBQuoteSpecial(char *string);
#
sub DBQuoteSpecial($)
{
...
...
@@ -625,5 +626,16 @@ sub DBQuoteSpecial($)
return $string;
}
#
# Return a (current) string suitable for DB insertion in datetime slot.
# Of course, you can use this for anything you like!
#
# usage: char *DBDateTime();
#
sub DBDateTime()
{
return strftime("20%y-%m-%d %H:%M:%S", localtime());
}
1;
tbsetup/batch_daemon.in
View file @
f2ef059a
...
...
@@ -155,10 +155,7 @@ while (1) {
# Local vars!
my
$eid
=
$pending_row
{'
eid
'};
my
$pid
=
$pending_row
{'
pid
'};
my
$now
=
`
date '+20%y-%m-%d %H:%M:%S'
`;
if
(
$now
=~
/^([-\@\w: ]+)$/
)
{
$now
=
$
1
;
}
my
$now
=
DBDateTime
();
$query_result
=
DBQuery
("
update batch_experiments set status='configuring',
"
.
...
...
@@ -319,15 +316,11 @@ sub startexp($)
my
$longname
=
$exphash
{'
name
'};
my
$attempts
=
$exphash
{'
attempts
'};
my
$expires
=
$exphash
{'
expires
'};
my
$rightnow
=
DBDateTime
();
#
# Insert an experiment record for startexp.
#
my
$rightnow
=
`
date '+20%y-%m-%d %H:%M:%S'
`;
if
(
$rightnow
=~
/^([-\@\w: ]+)$/
)
{
$rightnow
=
$
1
;
}
$query_result
=
DBQueryFatal
("
insert into experiments
"
.
"
(eid, pid, expt_created, expt_name,
"
.
...
...
tbsetup/batchexp.in
View file @
f2ef059a
...
...
@@ -176,12 +176,9 @@ if (system("$parser -n -a $nsfile") != 0) {
}
#
# Gen up the creation time.
# Gen up the creation time
for the batch record
.
#
$created
=
`
date '+%Y:%m:%d %H:%M:%S'
`;
if
(
$created
=~
/^([-\@\w: ]+)$/
)
{
$created
=
$
1
;
}
$created
=
DBDateTime
();
#
# Insert the record. We leave this to very last cause the batch daemon
...
...
tbsetup/endexp.in
View file @
f2ef059a
...
...
@@ -168,7 +168,7 @@ if ($estate eq EXPTSTATE_PRERUN ||
#
# Set the timestamp now, and unlock the experiments table.
#
$stamp
=
`
date '+20%y-%m-%d %H:%M:%S'
`
;
$stamp
=
DBDateTime
()
;
DBQueryFatal
("
UPDATE experiments SET expt_terminating='
$stamp
'
"
.
"
WHERE eid='
$eid
' and pid='
$pid
'
");
...
...
tbsetup/libtestbed.pm
View file @
f2ef059a
...
...
@@ -7,7 +7,7 @@ use Exporter;
@ISA
=
"
Exporter
";
@EXPORT
=
qw (
SENDMAIL
OPENMAIL
TBTimeStamp
TBBackGround
);
qw (
SENDMAIL
OPENMAIL
TBTimeStamp
TBBackGround
TBDateTimeFSSafe
);
# A library of useful stuff.
...
...
@@ -91,6 +91,17 @@ sub TBTimeStamp()
return
POSIX::
strftime
("
%H:%M:%S
",
localtime
());
}
#
# Another routine for creating a file name based on the current date and
# time. The format is slightly different so that it can be a proper filename.
#
# usage: char *TBDateTimeFSSafe()
#
sub
TBDateTimeFSSafe
()
{
return
POSIX::
strftime
("
20%y%m%d-%H.%M.%S
",
localtime
());
}
#
# Put ourselves into the background, directing output to the log file.
# The caller provides the logfile name, which should have been created
...
...
tbsetup/mkacct-ctrl.in
View file @
f2ef059a
...
...
@@ -14,11 +14,11 @@ use English;
#
my
$TB
=
"
@prefix
@
";
my
$TBOPS
=
"
@TBOPSEMAIL
@
";
my
$CONTROL
=
"
@USERNODE
@
";
my
$HOMEDIR
=
"
/users
";
my
$PBAG
=
"
$TB
/sbin/paperbag
";
my
$SSH
=
"
$TB
/bin/sshtb
";
my
$CONTROL
=
"
users.emulab.net
";
my
$GROUPADD
=
"
/usr/sbin/pw groupadd
";
my
$USERADD
=
"
/usr/sbin/pw useradd
";
my
$USERMOD
=
"
/usr/sbin/pw usermod
";
...
...
tbsetup/mkprojdir.in
View file @
f2ef059a
#!/usr/local/bin/perl -wT
use
Mysql
;
use
English
;
#
...
...
tbsetup/node_update.in
View file @
f2ef059a
...
...
@@ -9,6 +9,9 @@ use Getopt::Std;
#
# XXX There is an inherent race condition with using this script. What if
# nodes are released while it is running?
#
# The output is all jumbled together since the updates are issued in parallel.
# Might be a pain when debugging.
#
# usage: node_update [-b] <pid> <eid>
#
...
...
@@ -122,6 +125,10 @@ if ($UID && ! TBAdmin()) {
}
}
#
# Batchmode (as from the web interface) goes to background and reports
# later via email.
#
if
(
$batchmode
)
{
#
# Create a temporary name for a log file.
...
...
@@ -152,6 +159,20 @@ if (system("$expsetup")) {
# Give ops a chance to react.
sleep
(
2
);
#
# A sanity check. Lets make sure the experiment is in the swapped in
# state so that we are not trying to update nodes that are still booting
# or swapping out, etc.
#
if
(
ExpState
(
$pid
,
$eid
)
ne
EXPTSTATE_ACTIVE
)
{
fatal
("
The experiment
$pid
/
$eid
must be fully activated first!
\n
"
.
"
Please try again later, after activation. The experiment leader
\n
"
.
"
will receive email notification when the experiment has been
\n
"
.
"
fully activated, or you can check the status via the web
"
.
"
interface.
\n
");
exit
(
1
);
}
#
# Get the list of nodes that need to be "updated."
#
...
...
tbsetup/reload_daemon.in
View file @
f2ef059a
...
...
@@ -200,8 +200,7 @@ while (1) {
next
;
}
}
$stamp
=
`
date '+20%y-%m-%d %H:%M:%S'
`;
chop
(
$stamp
);
$stamp
=
DBDateTime
();
print
"
Reload of
$node
has started at
$stamp
.
\n
";
...
...
@@ -218,8 +217,7 @@ while (1) {
print
"
DB Error getting reservation for
$node
. Waiting a bit
\n
";
next
;
}
$stamp
=
`
date '+20%y-%m-%d %H:%M:%S'
`;
chop
(
$stamp
);
$stamp
=
DBDateTime
();
if
(
!
$query_result
->
numrows
)
{
print
"
\n
Reload of
$node
appears to have finished at
$stamp
.
\n
";
...
...
tbsetup/rmacct-ctrl.in
View file @
f2ef059a
...
...
@@ -15,10 +15,10 @@ use English;
#
my
$TB
=
"
@prefix
@
";
my
$TBOPS
=
"
@TBOPSEMAIL
@
";
my
$CONTROL
=
"
@USERNODE
@
";
my
$HOMEDIR
=
"
/users
";
my
$SSH
=
"
$TB
/bin/sshtb
";
my
$CONTROL
=
"
users.emulab.net
";
my
$USERDEL
=
"
/usr/sbin/pw userdel
";
my
$GENELISTS
=
"
$TB
/sbin/genelists
";
...
...
@@ -132,17 +132,7 @@ if (system("$SSH $control_node '$USERDEL $user'")) {
#
# Rename the user directory instead of deleting it.
#
my
$newname
=
"
$HOMEDIR
/
$user
-
"
.
`
date +20%y%m%d-%H.%M.%S
`;
#
# Untaint the new name since it was constructed with date. Dopey.
#
if
(
$newname
=~
/^([-\w.\/]+)$/
)
{
$newname
=
$
1
;
}
else
{
fatal
("
Tainted newname
$newname
");
}
my
$newname
=
"
$HOMEDIR
/
$user
-
"
.
TBDateTimeFSSafe
();
if
(
!
-
e
"
$HOMEDIR
/
$user
")
{
fatal
("
User directory '
$HOMEDIR
/
$user
' does not exist!
");
...
...
tbsetup/rmproj.in
View file @
f2ef059a
#!/usr/local/bin/perl -wT
use
Mysql
;
use
English
;
#
# Remove a project. We delete the project directory hierarchy and the
# we remove the group from /etc/group. Actually, the project directory
# is *renamed* from $pid to $pid-`date +20%y%m%d-%H.%M.%S` since we do
# not want to be so destructive.
# is *renamed* since we do not want to be so destructive.
#
# usage: rmprojdir <pid>
#
...
...
@@ -16,18 +14,31 @@ use English;
#
# Configure variables
#
my
$TB
=
"
@prefix
@
";
my
$
DBNAME
=
"
@TBDBNAME
@
";
my
$
SSH
=
"
$TB
/bin/sshtb
";
my
$TB
=
"
@prefix
@
";
my
$
TBOPS
=
"
@TBOPSEMAIL
@
";
my
$
CONTROL
=
"
@USERNODE
@
";
# un-taint path
$ENV
{'
PATH
'}
=
'
/bin:/usr/bin
';
my
$PROJROOT
=
"
/proj
";
my
$SSH
=
"
$TB
/bin/sshtb
";
my
$GROUPDEL
=
"
/usr/sbin/pw groupdel
";
#
# Untaint the path
#
$ENV
{'
PATH
'}
=
"
/bin:/usr/bin
";
delete
@ENV
{'
IFS
',
'
CDPATH
',
'
ENV
',
'
BASH_ENV
'};
my
$PROJROOT
=
"
/proj
";
my
$dbh
=
Mysql
->
connect
("
localhost
",
$DBNAME
,"
script
","
none
");
my
$db_result
=
"";
my
$control_node
=
"
plastic.emulab.net
";
#
# Turn off line buffering on output
#
$|
=
1
;
#
# Load the Testbed support stuff.
#
use
lib
"
@prefix
@/lib
";
use
libdb
;
use
libtestbed
;
#
# Check args.
...
...
@@ -51,52 +62,35 @@ else {
# Figure out who called us. Only root or people with admin status
# can run this script.
#
if
(
$UID
!=
0
)
{
my
(
$me
)
=
getpwuid
(
$UID
)
or
die
"
$UID
not in passwd file
";
$db_result
=
$dbh
->
query
("
select admin from users where uid='
$me
'
");
my
@row
=
$db_result
->
fetchrow_array
();
if
(
$row
[
0
]
!=
1
)
{
die
("
rmprojdir:
"
.
"
You must be root or TB admin to remove a project directory
\n
");
}
if
(
$UID
&&
!
TBAdmin
(
$UID
))
{
die
("
*** You must be root or TB admin to remove a project directory
\n
");
}
#
# Ensure that the project is not in the database!
#
$db_result
=
$dbh
->
query
("
select head_uid
"
.
"
from projects where pid='
$pid
'
");
if
(
$db_result
->
numrows
==
1
)
{
die
("
Project '
$pid
' is still in the database!
\n
");
my
$query_result
=
DBQueryFatal
("
select head_uid from projects where pid='
$pid
'
");
if
(
$query_result
->
numrows
)
{
die
("
*** Project '
$pid
' is still in the database!
\n
");
}
#
# Rename the project directory.
#
my
$newname
=
"
$pid
-
"
.
`
date +20%y%m%d-%H.%M.%S
`;
#
# Untaint the new name since it was constructed with date. Dopey.
#
if
(
$newname
=~
/^([-\@\w.]+)$/
)
{
$newname
=
$
1
;
}
my
$newname
=
"
$pid
-
"
.
TBDateTimeFSSafe
();
if
(
!
chdir
(
$PROJROOT
))
{
print
STDOUT
"
Could not chdir to
$PROJROOT
!
\n
";
exit
(
-
1
);
die
("
*** Could not chdir to
$PROJROOT
: $!
\n
");
}
if
(
!
-
e
$pid
)
{
print
STDOUT
"
Project directory '
$pid
' does not exist!
\n
";
exit
(
-
1
);
die
("
*** Project directory '
$pid
' does not exist!
\n
");
}
if
(
!
rename
(
$pid
,
$newname
))
{
print
STDOUT
"
Could not rename project directory
$pid
to
$newname
: $!
\n
";
exit
(
-
1
);
die
("
*** Could not rename project directory
$pid
to
$newname
: $!
\n
");
}
#
...
...
@@ -104,20 +98,17 @@ if (! rename($pid, $newname)) {
# allowed to look inside.
#
if
(
!
chmod
(
0700
,
$newname
))
{
print
STDOUT
"
Could not chmod directory
$newname
to 0700: $!
\n
";
exit
(
-
1
);
die
("
*** Could not chmod directory
$newname
to 0700: $!
\n
");
}
if
(
!
chown
(
0
,
0
,
$newname
))
{
print
STDOUT
"
Could not chown directory
$newname
to 0/0: $!
\n
";
exit
(
-
1
);
die
("
*** Could not chown directory
$newname
to 0/0: $!
\n
");
}
#
# Now remove the group from the group file on both plastic and paper.
#
if
(
system
("
/usr/sbin/pw groupdel
$pid
"))
{
print
STDOUT
"
Could not remove group
$pid
fron operatons node (paper)
\n
";
exit
(
-
1
);
if
(
system
("
$GROUPDEL
$pid
"))
{
die
("
*** Could not remove group
$pid
fron operatons node (paper)
\n
");
}
#
...
...
@@ -125,9 +116,8 @@ if (system("/usr/sbin/pw groupdel $pid")) {
#
$UID
=
0
;
if
(
system
("
$SSH
$control_node
/usr/sbin/pw groupdel
$pid
"))
{
print
STDOUT
"
Could not remove group
$pid
fron control node (plastic)
\n
";
exit
(
-
1
);
if
(
system
("
$SSH
$CONTROL
$GROUPDEL
$pid
"))
{
die
("
*** Could not remove group
$pid
fron control node (
$CONTROL
)
\n
");
}
exit
(
0
);
...
...
tbsetup/savevlans.in
View file @
f2ef059a
...
...
@@ -4,40 +4,42 @@
# "load data infile '$name' replace into table vlans;"
#
my
$TBROOT
=
"
@prefix
@
";
my
$DBNAME
=
"
@TBDBNAME
@
";
use
Mysql
;
my
$dbh
;
my
$sth
;
#
# Configure variables
#
my
$TBROOT
=
"
@prefix
@
";
my
$TESTMODE
=
@TESTMODE@
;
my
$d
=
0
;
#
# Untaint the path
#
$ENV
{'
PATH
'}
=
"
/bin:/usr/bin
";
delete
@ENV
{'
IFS
',
'
CDPATH
',
'
ENV
',
'
BASH_ENV
'};
$dbh
=
Mysql
->
connect
("
localhost
",
$DBNAME
,"
script
","
none
");
#
# Turn off line buffering on output
#
$|
=
1
;
$ENV
{'
PATH
'}
=
'
@prefix@/sbin:@prefix@/bin:/bin
';
#
# Load the Testbed support stuff.
#
use
lib
"
@prefix
@/lib
";
use
libdb
;
use
libtestbed
;
my
$time
=
`
date +20%y%m%d-%H.%M.%S
`;
chomp
(
$time
);
my
$name
=
"
vlans-
$time
";
$name
=~
/^([a-zA-Z\/_\-0-9:\.\'\"]*).*$/
;
$name
=
$
1
;
# Gen up a file name. Technically unsafe, but not likely to be a problem.
my
$name
=
"
vlans-
"
.
TBDateTimeFSSafe
();
print
"
Saving VLAN configuration to '
$name
'
\n
";
my
$cmd
=
"
select * from vlans into outfile '/tmp/
$name
'
";
if
(
!
(
$sth
=
$dbh
->
query
(
$cmd
))
)
{
die
("
Failed SQL Command:
\n
$cmd
\n
Error string is:
"
.
$dbh
->
errstr
.
"
\n
");
}
system
("
ls -l /tmp/vlan*
")
if
$d
;
DBQueryFatal
("
select * from vlans into outfile '/tmp/
$name
'
");
system
("
mv /tmp/
$name
$TBROOT
/backup/
")
&&
# If it doesn't return 0, it failed
die
("
Could
n'
t move /tmp/
$name
to
$TBROOT
/backup/
: $!
");
system
("
mv /tmp/
$name
$TBROOT
/backup/
$name
")
&&
die
("
***
Could
no
t move /tmp/
$name
to
$TBROOT
/backup/
$name
!
\n
");
system
("
ls -l
$TBROOT
/backup/
$name
")
if
$d
;
chown
(
0
,
601
,
"
$TBROOT
/backup/
$name
");
system
("
ls -l
$TBROOT
/backup/
$name
")
if
$d
;
chmod
(
0444
,
"
$TBROOT
/backup/
$name
")
;
system
("
ls -l
$TBROOT
/backup/
$name
")
if
$d
;
chown
(
0
,
601
,
"
$TBROOT
/backup/
$name
")
||
die
("
*** Could not chown
$TBROOT
/backup/
$name
: $!
\n
");
chmod
(
0444
,
"
$TBROOT
/backup/
$name
")
||
die
("
*** Could not chmod
$TBROOT
/backup/
$name
: $!
\n
")
;
tbsetup/startexp.in
View file @
f2ef059a
...
...
@@ -269,30 +269,22 @@ $expt_expires = $row[2];
#
# Gen up a date for the started field of the record, and insert it.
#
$expt_started
=
`
date '+20%y-%m-%d %H:%M:%S'
`;
if
(
$expt_started
=~
/^([-\@\w: ]+)$/
)
{
$expt_started
=
$
1
;
DBQueryWarn
("
update experiments set expt_start='
$expt_started
'
"
.
"
WHERE eid='
$eid
' and pid='
$pid
'
");
}
$expt_started
=
DBDateTime
();
DBQueryWarn
("
update experiments set expt_start='
$expt_started
'
"
.
"
WHERE eid='
$eid
' and pid='
$pid
'
");
print
STDOUT
"
Setup Success
\n
";
#
# Try to copy off the files for testbed information gathering.
#
my
$infodir
=
"
$pid
-
$eid
-
"
.
`
date +20%y%m%d-%H.%M.%S
`
;
my
$infodir
=
"
$pid
-
$eid
-
"
.
TBDateTimeFSSafe
()
;
if
(
$infodir
=~
/^([-\@\w.]+)$/
)
{
$infodir
=
$
1
;
if
(
mkdir
("
$TBINFO
/
$infodir
",
0770
))
{
system
("
cp
$nsfile
$TBINFO
/
$infodir
");
system
("
cp *.ptop *.top
$TBINFO
/
$infodir
");
system
("
cp assign.log
$TBINFO
/
$infodir
");
system
("
cp
$logname
$TBINFO
/
$infodir
/
$eid
.log
");
}
if
(
mkdir
("
$TBINFO
/
$infodir
",
0770
))
{
system
("
cp
$nsfile
$TBINFO
/
$infodir
");
system
("
cp *.ptop *.top
$TBINFO
/
$infodir
");
system
("
cp assign.log
$TBINFO
/
$infodir
");
system
("
cp
$logname
$TBINFO
/
$infodir
/
$eid
.log
");
}
#
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment