Commit 286e2019 authored by Kirk Webb's avatar Kirk Webb
Browse files

Forgot to check this stuff in last week:

Slothd changes to force an initial wait of <interval> (def 1hr).  Selectable
with -w.  Also changed to scan ALL ttys by default (can use UTMP with -a).

Finally, deploy script changed a bit to be more robust wrt down nodes.
parent 69ebc120
......@@ -32,7 +32,7 @@ sdcollectd: sdcollectd.o sdcollectd.h
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ sdcollectd.o $(SDLIBS)
islinux:
@uname -s | grep linux > /dev/null
@uname -s | grep inux > /dev/null
isfbsd:
@uname -s | grep BSD > /dev/null
......@@ -40,5 +40,5 @@ isfbsd:
install:
clean:
rm -f *.o $(PROGS) *~ core *.core linux/slothd fbsd/slothd
rm -f *.o $(PROGS) *~ core *.core
......@@ -8,13 +8,14 @@ use Getopt::Long;
use strict;
sub usage() {
print "Usage: $0 [-e <pid> <eid>] | [vnode ...]\n";
print "Usage: $0 [-a] | [-e <pid> <eid>] | [vnode ...]\n";
}
my %opts = ();
my $pid;
my $eid;
my @nodes = ();
my @failed = ();
if (@ARGV < 1) {
exit &usage;
......@@ -28,15 +29,37 @@ my $fbsdrcpath = "~kwebb/src/testbed/tmcd/freebsd/rc.testbed";
my $SSH = "sudo ssh -q";
my $SCP = "sudo scp -q -o Loglevel=QUIET";
GetOptions(\%opts,'h','e=s');
GetOptions(\%opts,'h','f=s','e=s','a');
if ($opts{"e"}) {
if ($opts{"f"}) {
open(NODEFILE, "<$opts{'f'}");
while (<NODEFILE>) {
chomp;
push @nodes, $_;
}
}
elsif ($opts{"a"}) {
my $qres = DBQuery("select a.node_id from reserved as a "
. "left join nodes as b "
. "on a.node_id = b.node_id "
. "where b.type = 'pc850' or b.type = 'pc600'");
if ($qres) {
while(my @row = $qres->fetchrow_array()) {
push @nodes, $row[0];
}
}
}
elsif ($opts{"e"}) {
$pid = $opts{"e"};
$eid = shift;
@nodes = ExpNodes($pid, $eid);
print "pid: $pid\n";
print "eid: $eid\n";
} else {
}
else {
@nodes = @ARGV;
}
......@@ -44,28 +67,58 @@ print "Installing on the following nodes: @nodes\n";
my $j;
foreach $j (@nodes) {
InstallSlothd($j);
if (InstallSlothd($j)) {
push @failed, $j;
}
}
if (@failed) {
print "failed nodes: @failed\n\n";
}
exit 0;
sub InstallSlothd($) {
my $node = shift;
my $nodeos;
my $nodeos = "";
print "Executing for $node ...\n";
print "pinging node..\n";
`ping -q -c 2 $node > /dev/null`;
if ($?) {
print "host down.. skipping.\n";
return 1;
}
$nodeos = `$SSH $node uname -s`;
if ($nodeos =~ /inux/) {
if ($nodeos =~ /linux/i) {
print "Node type is linux\n";
print "stopping slothd on $node\n";
`$SSH $node killall slothd`;
sleep 1;
`$SCP $linpath $node:/etc/rc.d/testbed`;
`$SCP $linrcpath $node:/etc/rc.d/testbed`;
`$SCP $linrcpath $node:/etc/rc.d/testbed`;
}
else {
elsif ($nodeos =~ /freebsd/i) {
print "Node type is FreeBSD\n";
print "stopping slothd on $node\n";
`$SSH $node killall slothd`;
sleep 1;
`$SCP $fbsdpath $node:/etc/testbed`;
`$SCP $fbsdrcpath $node:/etc/testbed`;
}
else {
print "Unknown node OS: $nodeos: not deploying.\n";
return 1;
}
print "starting slothd on $node\n";
`$SSH $node /etc/testbed/slothd`;
if ($?) {
return 1;
}
return 0;
}
exit 0;
......@@ -39,7 +39,8 @@ void usage(void) {
printf("Usage:\tslothd -h\n");
printf("\tslothd [-a] [-d] [-i <interval>] [-p <port>] [-s <server>]\n");
printf("\t -h\t This message.\n");
printf("\t -a\t Scan all terminal special files for activity.\n");
printf("\t -a\t Only scan active terminal special files.\n");
printf("\t -f\t Send first idle data report immediately on startup.\n");
printf("\t -d\t Debug mode; do not fork into background.\n");
printf("\t -i <interval>\t Run interval, in seconds. (default is 10 min.)\n");
printf("\t -p <port>\t Send on port <port> (default is %d).\n", SLOTHD_DEF_PORT);
......@@ -69,11 +70,16 @@ int main(int argc, char **argv) {
else {
exitcode = 0;
for (i = 0; i < 10; ++i) {
get_min_tty_idle();
if (!opts->first) {
sleep(mopts.interval);
}
get_load();
get_min_tty_idle();
get_packet_counts();
send_pkt();
sleep(mopts.interval);
if (opts->first) {
sleep(mopts.interval);
}
}
}
}
......@@ -87,12 +93,13 @@ int parse_args(int argc, char **argv) {
/* setup defaults. */
opts->debug = 0;
opts->allterms = 0;
opts->actterms = 0;
opts->interval = DEF_INTVL;
opts->port = SLOTHD_DEF_PORT;
opts->servname = SLOTHD_DEF_SERV;
opts->first = 0;
while ((ch = getopt(argc, argv, "ai:dp:s:h")) != -1) {
while ((ch = getopt(argc, argv, "ai:dp:s:hf")) != -1) {
switch (ch) {
case 'i':
......@@ -108,8 +115,12 @@ int parse_args(int argc, char **argv) {
break;
case 'a':
lnotice("Scanning all terminal devices (ignoring UTMP).");
opts->allterms = 1;
lnotice("Scanning only active terminals.");
opts->actterms = 1;
break;
case 'f':
opts->first = 1;
break;
case 'p':
......@@ -161,7 +172,7 @@ int init_slothd(void) {
}
/* enum tty special files, if necessary. */
if (opts->allterms) {
if (!opts->actterms) {
if ((devs = opendir("/dev")) == 0) {
lerror("Can't open directory /dev for processing");
return -1;
......@@ -213,7 +224,7 @@ void get_min_tty_idle(void) {
time_t mintime = 0;
struct stat sb;
if (!opts->allterms) {
if (opts->actterms) {
utmp_enum_terms();
if (!opts->numttys) {
mintime = wtmp_get_last();
......
......@@ -74,7 +74,8 @@ typedef struct {
u_int interval;
u_short numttys;
u_char debug;
u_char allterms;
u_char actterms;
u_char first;
char *servname;
u_short port;
char *ttys[MAXTTYS];
......
Supports Markdown
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