Commit 7c481b95 authored by Leigh Stoller's avatar Leigh Stoller

New rc script to start up the link agent on non-ethernet (okay,

wireless) nodes.
parent 9149eed0
......@@ -19,7 +19,8 @@ SUBDIR = tmcd/common/config
SCRIPTS = $(addprefix $(SRCDIR)/, \
rc.config rc.misc rc.mounts rc.accounts rc.route \
rc.tunnels rc.ifconfig rc.delays rc.hostnames rc.syncserver \
rc.tunnels rc.ifconfig rc.delays rc.hostnames \
rc.syncserver rc.linkagent \
rc.keys rc.trafgen rc.tarfiles rc.rpms rc.progagent \
rc.startcmd rc.simulator)
......
......@@ -87,8 +87,8 @@ else {
@bootscripts = ("rc.misc", "rc.keys", "rc.mounts", "rc.accounts",
"rc.route", "rc.tunnels", "rc.ifconfig", "rc.delays",
"rc.hostnames", "rc.syncserver", "rc.trafgen",
"rc.tarfiles", "rc.rpms", "rc.progagent", "rc.startcmd",
"rc.simulator");
"rc.tarfiles", "rc.rpms", "rc.progagent", "rc.linkagent",
"rc.startcmd", "rc.simulator");
}
# Execute the action.
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2004 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
sub usage()
{
print "Usage: " .
scriptname() . " [-j vnodeid] boot|shutdown|reconfig|reset\n";
exit(1);
}
my $optlist = "j:";
my $action = "boot";
# Turn off line buffering on output
$| = 1;
# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
# Only root.
if ($EUID != 0) {
die("*** $0:\n".
" Must be root to run this script!\n");
}
# Script specific goo
my $LOGFILE = "$LOGDIR/linkagent.debug";
my $PIDFILE = "/var/run/linkagent.pid";
my $LAGENT = "$BINDIR/link-agent";
#
# Load the OS independent support library. It will load the OS dependent
# library and initialize itself.
#
use libsetup;
use libtmcc;
use librc;
#
# Not all clients support this.
#
exit(0)
if (MFS() || JAILED() || REMOTE());
# Protos.
sub doboot();
sub doshutdown();
sub doreconfig();
sub docleanup();
# Parse command line.
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{'j'})) {
my $vnodeid = $options{'j'};
libsetup_setvnodeid($vnodeid);
}
# Allow default above.
if (@ARGV) {
$action = $ARGV[0];
}
# Execute the action.
SWITCH: for ($action) {
/^boot$/i && do {
doboot();
last SWITCH;
};
/^shutdown$/i && do {
doshutdown();
last SWITCH;
};
/^reconfig$/i && do {
doreconfig();
last SWITCH;
};
/^reset$/i && do {
docleanup();
last SWITCH;
};
fatal("Invalid action: $action\n");
}
exit(0);
#
# Boot Action.
#
sub doboot()
{
my @ifacelist = ();
my $args = "";
#
# Get the iface list from libsetup, which handles parsing the stuff
# we get back from tmcd.
#
if (getifconfig(\@ifacelist) != 0) {
fatal("Could not get ifconfig from libsetup!");
}
return 0
if (! @ifacelist);
#
# Need the pid/eid and nickname.
#
my ($pid, $eid, $vname) = check_nickname();
$vname = $vnodeid
if (defined($vnodeid));
foreach my $ifconfig (@ifacelist) {
my $lan = $ifconfig->{"LAN"};
my $iface = $ifconfig->{"IFACE"};
my $mac = $ifconfig->{"MAC"};
my $protocol = $ifconfig->{"SETTINGS"}->{"protocol"};
# We want to run this for non-ethernet links only since eth links
# are handled by the delay agent.
next
if (!defined($protocol) || $protocol eq "ethernet");
$args .= " $lan,$vname,$iface,$mac";
}
return 0
if ($args eq "");
print "Starting Link Agent ...\n";
system("$LAGENT -v -e $pid/$eid -s localhost -l $LOGFILE ".
"-i $PIDFILE -k " . TMEVENTKEY() . "$args\n");
if ($?) {
fatal("Could not start program agent!");
}
return;
}
#
# Shutdown Action.
#
sub doshutdown()
{
#
# Kill the process.
#
if (-e $PIDFILE) {
system("kill `cat $PIDFILE`");
# Does not unlink its own pidfile.
unlink $PIDFILE;
}
return;
}
#
# Node Reconfig Action (without rebooting).
#
sub doreconfig()
{
# Same as booting
doshutdown();
return doboot();
}
#
# Node cleanup action (node is reset to clean state, as if just allocated).
#
sub docleanup()
{
# Remove config file; will be regenerated at next boot.
if (-e $CONFIG) {
unlink $CONFIG;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment