Commit c733dd14 authored by Leigh Stoller's avatar Leigh Stoller

Add wrapper script around dhcpd to restart it if it dies; whenever dhcpd dies,...

Add wrapper script around dhcpd to restart it if it dies; whenever dhcpd dies, the testbed becomes unusable.
parent b51013db
......@@ -1470,14 +1470,14 @@ outfiles="$outfiles Makeconf GNUmakefile \
utils/firstuser utils/export_tables utils/eventping \
utils/cvsupd.pl utils/newnode utils/grantnodetype \
utils/nsgen/GNUmakefile utils/nsgen/webnsgen \
utils/link_config utils/import_commitlog \
utils/link_config utils/import_commitlog utils/dhcp_wrapper \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 \
www/swish.conf www/websearch \
vis/GNUmakefile vis/webvistopology vis/dbvistopology \
vis/prerender vis/prerender_all vis/render \
vis/floormap vis/webfloormap \
rc.d/GNUmakefile rc.d/2.mysql-server.sh rc.d/3.testbed.sh \
rc.d/2.elvind.sh rc.d/3.plab.sh \
rc.d/2.elvind.sh rc.d/3.plab.sh rc.d/2.dhcpd.sh \
tools/GNUmakefile \
tools/pcapper/GNUmakefile tools/teachswitch/GNUmakefile \
$eventfiles \
......
......@@ -515,14 +515,14 @@ outfiles="$outfiles Makeconf GNUmakefile \
utils/firstuser utils/export_tables utils/eventping \
utils/cvsupd.pl utils/newnode utils/grantnodetype \
utils/nsgen/GNUmakefile utils/nsgen/webnsgen \
utils/link_config utils/import_commitlog \
utils/link_config utils/import_commitlog utils/dhcp_wrapper \
www/GNUmakefile www/defs.php3 www/dbdefs.php3 \
www/swish.conf www/websearch \
vis/GNUmakefile vis/webvistopology vis/dbvistopology \
vis/prerender vis/prerender_all vis/render \
vis/floormap vis/webfloormap \
rc.d/GNUmakefile rc.d/2.mysql-server.sh rc.d/3.testbed.sh \
rc.d/2.elvind.sh rc.d/3.plab.sh \
rc.d/2.elvind.sh rc.d/3.plab.sh rc.d/2.dhcpd.sh \
tools/GNUmakefile \
tools/pcapper/GNUmakefile tools/teachswitch/GNUmakefile \
$eventfiles \
......
#!/bin/sh
#
# Wrapper for DHCPD which has a habit of dying.
#
case "$1" in
start)
if [ -x @prefix@/sbin/dhcpd_wrapper ]; then
echo -n " dhcpd_wrapper"
@prefix@/sbin/dhcpd_wrapper
fi
;;
stop)
if [ -r /var/run/dhcpd_wrapper.pid ]; then
kill `cat /var/run/dhcpd_wrapper.pid`
fi
;;
*)
echo ""
echo "Usage: `basename $0` { start | stop }"
echo ""
exit 64
;;
esac
......@@ -8,7 +8,8 @@ SUBDIR = rc.d
include $(OBJDIR)/Makeconf
RC_SCRIPTS = 2.mysql-server.sh 3.testbed.sh 2.elvind.sh 1.named.sh
RC_SCRIPTS = 2.mysql-server.sh 3.testbed.sh 2.elvind.sh 1.named.sh \
2.dhcpd.sh
#
# Force dependencies to make sure configure regenerates if the .in file
......
......@@ -16,7 +16,7 @@ SUBDIRS = nsgen
BIN_SCRIPTS = delay_config sshtb create_image node_admin link_config
SBIN_SCRIPTS = vlandiff vlansync withadminprivs export_tables cvsupd.pl \
eventping grantnodetype import_commitlog
eventping grantnodetype import_commitlog dhcpd_wrapper
LIBEXEC_SCRIPTS = webcreateimage newnode
#
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2004 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
use POSIX qw(setsid);
sub usage()
{
print "Usage: dhcpd_wrapper\n";
exit(1);
}
my $optlist = "";
my $debug = 0;
my $TBOPS = "@TBOPSEMAIL@";
my $PIDFILE = "/var/run/dhcpd_wrapper.pid";
my $LOGFILE = "/var/log/dhcpd_wrapper.log";
my $DHCPD = "/usr/local/sbin/dhcpd -f ";
#my $DHCPDOPTS = "-cf /usr/local/etc/dhcpd.conf.v3 fxp0";
my $DHCPDOPTS = "";
my $childpid;
# Turn off line buffering on output
$| = 1;
# Only root.
if ($UID != 0) {
die("*** $0:\n".
" Must be root to run this script!\n");
}
#
# Testbed support libs.
#
use lib "@prefix@/lib";
use libtestbed;
# Signal handler to initiate cleanup in parent and the children.
sub Pcleanup($)
{
my ($signame) = @_;
$SIG{TERM} = 'IGNORE';
if (defined($childpid)) {
system("kill $childpid");
waitpid($childpid, 0);
}
unlink $PIDFILE;
exit(0);
}
# Daemonize;
if (!$debug && TBBackGround($LOGFILE)) {
sleep(1);
exit(0);
}
$SIG{TERM} = \&Pcleanup;
# Fully disconnect from bootup.
setsid();
# Loop forever, restarting DHCPD if it ever dies.
while (1) {
$childpid = fork();
$SIG{TERM} = 'IGNORE';
die("*** $0:\n".
" Could not fork!\n")
if ($childpid < 0);
if ($childpid == 0) {
exec("$DHCPD $DHCPDOPTS");
die("*** $0:\n".
" Could not exec $DHCPD!\n");
}
waitpid($childpid, 0);
#
# Anytime it exits, send email.
#
SENDMAIL($TBOPS, "DHCPD died",
"$DHCPD died with $?; restarting it.",
$TBOPS);
sleep(1);
}
exit(0);
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