Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
17b80181
Commit
17b80181
authored
Feb 21, 2001
by
Leigh B. Stoller
Browse files
Add named map munging script, called from tbrun and tbend.
parent
a1c93015
Changes
6
Hide whitespace changes
Inline
Side-by-side
configure
View file @
17b80181
...
...
@@ -936,6 +936,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/ns2ir/postparse tbsetup/ir/handle_os tbsetup/ir/handle_ip
\
tbsetup/ns2ir/parse.tcl tbsetup/savevlans
\
tbsetup/tbprerun tbsetup/tbrun tbsetup/tbend tbsetup/tbreport
\
tbsetup/named_setup
\
tbsetup/checkpass/GNUmakefile
\
tip/GNUmakefile
\
tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile
\
...
...
configure.in
View file @
17b80181
...
...
@@ -103,6 +103,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/ns2ir/parse.tcl tbsetup/ns2ir/tb_compat.tcl.in \
tbsetup/savevlans tbsetup/ir/extract_tb.in \
tbsetup/tbprerun tbsetup/tbrun tbsetup/tbend tbsetup/tbreport \
tbsetup/named_setup \
tbsetup/checkpass/GNUmakefile \
tip/GNUmakefile \
tmcd/GNUmakefile tmcd/freebsd/GNUmakefile tmcd/linux/GNUmakefile \
...
...
tbsetup/GNUmakefile.in
View file @
17b80181
...
...
@@ -13,7 +13,7 @@ SUBDIRS = checkpass ir ns2ir
BIN_STUFF = power snmpit tbend tbrun tbprerun tbreport \
vpower vsnmpit os_load savevlans
SBIN_STUFF = resetvlans console_setup.proxy sched_reload
SBIN_STUFF = resetvlans console_setup.proxy sched_reload
named_setup
LIBEXEC_STUFF = mkprojdir rmproj mkacct-ctrl rmacct-ctrl \
os_setup mkexpdir tbdoit tbstopit console_setup
...
...
@@ -67,6 +67,8 @@ post-install:
chmod u+s $(INSTALL_LIBEXECDIR)/rmacct-ctrl
chown root $(INSTALL_LIBEXECDIR)/os_setup
chmod u+s $(INSTALL_LIBEXECDIR)/os_setup
chown root $(INSTALL_SBINDIR)/named_setup
chmod u+s $(INSTALL_SBINDIR)/named_setup
chown root $(INSTALL_BINDIR)/os_load
chmod u+s $(INSTALL_BINDIR)/os_load
chown root $(INSTALL_BINDIR)/savevlans
...
...
tbsetup/named_setup.in
0 → 100644
View file @
17b80181
#!/usr/bin/perl -wT
use
English
;
use
Fcntl
'
:flock
';
#
# Suck out virtual names and create CNAME map entries.
#
# usage: named_setup
#
#
# Configure variables
#
my
$TB
=
"
@prefix
@
";
my
$DBNAME
=
"
@TBDBNAME
@
";
my
$mapdir
=
"
/etc/namedb
";
my
$mapfile
=
"
$mapdir
/emulab.db
";
my
$mapfileback
=
"
$mapdir
/emulab.db.backup
";
my
$mapfilehead
=
"
$mapdir
/emulab.db.head
";
my
$mapfiletail
=
"
$mapdir
/emulab.db.tail
";
my
$lockfile
=
"
/var/tmp/testbed_named_lockfile
";
my
$dbg
=
0
;
my
@row
;
# un-taint path
$ENV
{'
PATH
'}
=
'
/bin:/usr/bin:/usr/sbin:/usr/local/bin
';
delete
@ENV
{'
IFS
',
'
CDPATH
',
'
ENV
',
'
BASH_ENV
'};
$|
=
1
;
#Turn off line buffering on output
#
# Set up for querying the database.
#
use
Mysql
;
my
$DB
=
Mysql
->
connect
("
localhost
",
$DBNAME
,
"
script
",
"
none
");
#
# This script always does the right thing, so it does not matter who
# calls it.
#
#
# We need to serialize this script to avoid a trashed map file. Use
# a dummy file in /var/tmp, opened for writing and flock'ed.
#
open
(
LOCK
,
"
>>
$lockfile
")
||
fatal
("
Couldn't open
$lockfile
\n
");
$count
=
0
;
while
(
flock
(
LOCK
,
LOCK_EX
|
LOCK_NB
)
==
0
)
{
print
"
Another named map update in progress. Waiting a moment ...
\n
";
if
(
$count
++
>
20
)
{
fatal
("
Could not get the lock after a long time!
\n
");
}
sleep
(
1
);
}
#
# We stick the new map entries into the tail file. First zero it out.
#
open
(
MAP
,
"
>
$mapfiletail
")
||
fatal
("
Couldn't open
$mapfiletail
\n
");
print
MAP
"
\n
";
print
MAP
"
;
\n
";
print
MAP
"
; DO NOT EDIT below this point. Auto generated map entries!
\n
";
print
MAP
"
;
\n
";
print
MAP
"
\n
";
print
MAP
"
\$
TTL
\t
1
\n
";
#
# Figure out the set of nodes we are working on. These are the nodes
# that have a vname in the reserved table.
#
$db_result
=
$DB
->
query
("
select node_id,pid,eid,vname from reserved
"
.
"
where vname!=''
");
if
(
$db_result
->
numrows
>
0
)
{
#
# Create a CNAME for each reserved node.
#
while
(
@row
=
$db_result
->
fetchrow_array
)
{
my
$node_id
=
$row
[
0
];
my
$pid
=
$row
[
1
];
my
$eid
=
$row
[
2
];
my
$vname
=
$row
[
3
];
my
$cname
=
sprintf
("
%-40s
",
"
$vname
.
$eid
.
$pid
");
printf
MAP
"
$cname
IN
\t
CNAME
\t
$node_id
\n
";
}
}
print
MAP
"
\n
";
close
(
MAP
);
#
# Concat the head and tail files to create the new map.
#
if
(
-
e
$mapfile
)
{
system
("
mv
$mapfile
$mapfileback
")
==
0
or
fatal
("
Could not back up
$mapfile
to
$mapfileback
\n
");
}
#
# Generate a warning so that no one tries to edit the file by hand
#
open
(
MAP
,
"
>
$mapfile
")
||
fatal
("
Couldn't open
$mapfile
\n
");
print
MAP
"
;
\n
"
.
"
; ******************************************************************
\n
"
.
"
; DO NOT EDIT THIS FILE. IT IS A CREATION, A FIGMENT, A CONTRIVANCE!
\n
"
.
"
;
\n
"
.
"
; Edit the
\"
head
\"
file, then run
${TB}
bin/named_setup.
\n
"
.
"
; ******************************************************************
\n
"
.
"
;
\n
";
#
# Now copy in the head part of the map, looking for the serial
# number so it can be bumped up.
#
open
(
MAPHEAD
,
"
<
$mapfilehead
")
||
fatal
("
Couldn't open
$mapfilehead
\n
");
while
(
<
MAPHEAD
>
)
{
if
(
/Serial Number/i
)
{
my
$serial
=
`
date +%s
`;
chop
$serial
;
print
MAP
"
\t\t\t
$serial
\t
; Serial Number -- DO NOT EDIT
\n
";
}
else
{
print
MAP
"
$_
";
}
}
close
(
MAPHEAD
);
close
(
MAP
);
#
# Now the tail of the map.
#
system
("
cat
$mapfiletail
>>
$mapfile
")
==
0
or
fatal
("
Failed to concat
$mapfiletail
to
$mapfile
\n
");
#
# This is better than HUPing the nameserver.
#
system
("
named.reload > /dev/null
")
==
0
or
fatal
("
named.reload failed!
\n
");
exit
(
0
);
sub
fatal
{
local
(
$msg
)
=
$_
[
0
];
system
("
echo
\"
$msg
\"
| /usr/bin/mail
"
.
"
-s 'Named Setup Failed' stoller
\@
fast.cs.utah.edu
");
die
(
$msg
);
}
tbsetup/tbend.in
View file @
17b80181
...
...
@@ -62,6 +62,14 @@ if (&tbs_exec("nfree $pid $eid")) {
exit
(
1
);
}
&tbs_out
("
Resetting named maps
\n
");
if
(
&tbs_exec
("
named_setup
"))
{
&tbs_out
("
Failed to reset named map.
\n
");
#
# This is a non-fatal error.
#
}
&tbs_out
("
Cleanup finished -
"
.
&ctime
(
time
)
.
"
\n
");
0
;
...
...
tbsetup/tbrun.in
View file @
17b80181
...
...
@@ -57,6 +57,14 @@ if (&tbs_exec("os_setup $pid $eid $irfile")) {
exit
(
1
);
}
&tbs_out
("
Setting up named maps.
\n
");
if
(
&tbs_exec
("
named_setup
"))
{
&tbs_out
("
Failed to add node names to named map.
\n
");
#
# This is a non-fatal error.
#
}
&tbs_out
("
Run finished -
"
.
&ctime
(
time
)
.
"
\n
");
0
;
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