Commit 05fef6ed authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Remove -T option. Increase timeout to 12 hours again, now that we have

ntpdrift values reported from most nodes. Do not report ntpdrift from
the MFS either. Clean up pidfile stuff, and add better "stop" mode for
shutdown.
parent d1426d29
#!/usr/bin/perl -wT
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2002 University of Utah and the Flux Group.
......@@ -15,7 +15,7 @@ use POSIX qw(strftime);
#
sub usage()
{
print "Usage: watchdog [-d] [-t timeout]\n";
print "Usage: watchdog [-d] [-t timeout] [start | stop]\n";
exit(1);
}
my $optlist = "t:d";
......@@ -35,7 +35,8 @@ BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
use libsetup;
# Locals
my $timeout = (60 * 60 * 4); # In seconds of course.
my $action = "start";
my $timeout = (60 * 60 * 12); # In seconds of course.
my $logname = "$LOGDIR/emulab-watchdog.debug";
my $pidfile = "/var/run/emulab-watchdog.pid";
my $debug = 0;
......@@ -62,7 +63,11 @@ if (defined($options{"d"})) {
$debug = 1;
}
if (@ARGV) {
usage();
$action = $ARGV[0];
if (@ARGV != 1 || ($action ne "start" && $action ne "stop")) {
usage();
}
}
#
......@@ -73,6 +78,18 @@ if ($UID != 0) {
" Must be root to run this script!\n");
}
#
# For stop, look to see if the pid file exists. If so, kill it and exit.
#
if ($action eq "stop") {
if (! -e $pidfile) {
exit(0);
}
system("kill `cat $pidfile`");
sleep(1);
exit($? >> 8);
}
#
# Put this into the background and log its output. We *must* do this cause
# we do not want to halt the boot if the testbed is down!
......@@ -84,6 +101,14 @@ if (!$debug && TBBackGround($logname)) {
exit(0);
}
#
# Write our pid into the pid file so we can be killed later. We must
# do this first so that we can be killed before we change the sig
# handlers.
#
system("echo '$PID' > $pidfile") == 0
or die("Could not create $pidfile!");
#
# Setup a handler to catch TERM, and kill our process group.
#
......@@ -93,22 +118,13 @@ sub handler () {
$SIG{TERM} = 'IGNORE';
$SIG{INT} = 'IGNORE';
kill('TERM', -$pgrp);
unlink($pidfile);
sleep(5);
exit(0);
}
$SIG{TERM} = \&handler;
$SIG{INT} = \&handler;
#
# Write our pid into the pid file so we can be killed later (when the
# experiment is torn down). We must do this first so that we can be
# killed before we change the sig handlers
#
open(PFILE, "> $pidfile")
or die("Could not open $pidfile: $!");
print PFILE "$PID\n";
close(PFILE);
#
# Start isalive daemon.
#
......@@ -144,9 +160,9 @@ while (1) {
#
# Send back ntpdrift info. Should move elsewhere.
#
if (!REMOTE() && defined($driftfile)) {
if (!REMOTE() && !MFS() && defined($driftfile)) {
my $drift = `cat $driftfile`;
if ($drift =~ /^([\d\.]*)$/) {
if ($drift =~ /^([-\d\.]*)$/) {
# Server also checks the value for sanity.
system("tmcc -t 3 ntpdrift $1");
}
......
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