From c9489e4e441c95e9b39b3987e30166879d9ddac5 Mon Sep 17 00:00:00 2001
From: Mike Hibler <mike@flux.utah.edu>
Date: Thu, 14 Dec 2006 23:34:31 +0000
Subject: [PATCH] Started out as a small change to put a restart wrapper around
 opsrecv...

But opsrecv and friends were never officially installed, so took care of
that too (conditional on PELABSUPPORT in the defs file).
---
 configure                  | 22 +++++++++-------
 configure.in               |  4 ++-
 defs-default               |  7 ++---
 defs-elabinelab            |  1 +
 defs-example               | 18 +++++++++++--
 defs-example-privatecnet   | 18 +++++++++++--
 pelab/GNUmakefile.in       | 15 ++++++++++-
 pelab/bgmon/GNUmakefile.in | 31 ++++++++++++++++++++++
 rc.d/GNUmakefile.in        |  4 +++
 rc.d/pelab.sh.in           | 53 ++++++++++++++++++++++++++++++++++++++
 utils/GNUmakefile.in       |  2 +-
 utils/daemon_wrapper.in    | 21 ++++++++++++---
 12 files changed, 172 insertions(+), 24 deletions(-)
 create mode 100644 pelab/bgmon/GNUmakefile.in
 create mode 100644 rc.d/pelab.sh.in

diff --git a/configure b/configure
index f4dd080b5c..e7cae03674 100755
--- a/configure
+++ b/configure
@@ -2008,7 +2008,9 @@ fi
 if test $PELABSUPPORT -eq 0; then
 	pelabfiles="";
 else
-	pelabfiles="pelab/GNUmakefile pelab/db/GNUmakefile ";
+	pelabfiles="pelab/GNUmakefile pelab/db/GNUmakefile \
+		    pelab/bgmon/GNUmakefile ";
+	optional_subdirs="$optional_subdirs pelab";
 fi
 
 #
@@ -2052,17 +2054,17 @@ for ac_hdr in ulxmlrpcpp/ulxr_config.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:2056: checking for $ac_hdr" >&5
+echo "configure:2058: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2061 "configure"
+#line 2063 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2066: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2068: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -2101,17 +2103,17 @@ for ac_hdr in linux/videodev.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:2105: checking for $ac_hdr" >&5
+echo "configure:2107: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2110 "configure"
+#line 2112 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2115: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2117: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -2144,7 +2146,7 @@ done
 # Extract the first word of "gtk-config", so it can be a program name with args.
 set dummy gtk-config; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2148: checking for $ac_word" >&5
+echo "configure:2150: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_GTK_CONFIG'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2223,7 +2225,7 @@ fi
 # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
 # ./install, which can be erroneously created by make from ./install.sh.
 echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
-echo "configure:2227: checking for a BSD compatible install" >&5
+echo "configure:2229: checking for a BSD compatible install" >&5
 if test -z "$INSTALL"; then
 if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -2284,7 +2286,7 @@ esac
 # Extract the first word of "rsync", so it can be a program name with args.
 set dummy rsync; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:2288: checking for $ac_word" >&5
+echo "configure:2290: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_path_RSYNC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
diff --git a/configure.in b/configure.in
index 76fffd2ad3..16c0e996fa 100755
--- a/configure.in
+++ b/configure.in
@@ -620,7 +620,9 @@ AC_SUBST(EVENTSYS)
 if test $PELABSUPPORT -eq 0; then
 	pelabfiles="";
 else
-	pelabfiles="pelab/GNUmakefile pelab/db/GNUmakefile ";
+	pelabfiles="pelab/GNUmakefile pelab/db/GNUmakefile \
+		    pelab/bgmon/GNUmakefile ";
+	optional_subdirs="$optional_subdirs pelab";
 fi
 
 #
diff --git a/defs-default b/defs-default
index 3d60fd1e60..2ec7bbbc2f 100644
--- a/defs-default
+++ b/defs-default
@@ -35,12 +35,9 @@ FS_WITH_QUOTAS="/q /users"
 WWWHOST=www.emulab.net
 TBMAINSITE=1
 THISHOMEBASE=Emulab.Net
-PLABSUPPORT=1
-PLAB_ROOTBALL="plabroot-18.tar.bz2"
 MIN_UNIX_UID=10000
 MIN_UNIX_GID=6000
 WINSUPPORT=1
-PELABSUPPORT=1
 
 #
 # This next group will not work outside of Utah (yet).
@@ -54,6 +51,10 @@ CHATSUPPORT=1
 NFSTRACESUPPORT=1
 ARCHIVESUPPORT=1
 OPSDBSUPPORT=1
+PELABSUPPORT=1
+PLABSUPPORT=1
+PLAB_ROOTBALL="plabroot-18.tar.bz2"
+
 #
 # SSL Certificate stuff. Used to customize config files in ssl directory.
 # Note that OrganizationalUnit is set in the cnf file.
diff --git a/defs-elabinelab b/defs-elabinelab
index 795b26f4cf..1240012433 100644
--- a/defs-elabinelab
+++ b/defs-elabinelab
@@ -33,6 +33,7 @@ WWWHOST=changeme
 TBMAINSITE=0
 THISHOMEBASE=changeme
 PLABSUPPORT=0
+PELABSUPPORT=0
 WIKISUPPORT=changeme
 BUGDBSUPPORT=changeme
 MAILMANSUPPORT=changeme
diff --git a/defs-example b/defs-example
index ee8c605c56..0397e80ea8 100644
--- a/defs-example
+++ b/defs-example
@@ -225,6 +225,22 @@ VIRTNODE_NETMASK=255.240.0.0
 JAILIPBASE=$VIRTNODE_NETWORK
 JAILIPMASK=$VIRTNODE_NETMASK
 
+#
+# Only supported on the Mother Ship (emulab.net) right now.
+#
+WIKISUPPORT=0
+BUGDBSUPPORT=0
+MAILMANSUPPORT=0
+CVSSUPPORT=0
+CHATSUPPORT=0
+NFSTRACESUPPORT=0
+ARCHIVESUPPORT=0
+OPSDBSUPPORT=0
+SFSSUPPORT=0
+PELABSUPPORT=0
+PLABSUPPORT=0
+PLAB_ROOTBALL="plabroot-18.tar.bz2"
+
 #
 # You shouldn't have to change anything below this point
 #
@@ -233,7 +249,6 @@ TBADMINGROUP=tbadmin
 TBDBNAME=tbdb
 IPBASE=10
 DELAYCAPACITY=2
-SFSSUPPORT=0
 DISABLE_NSE=1
 FRISEBEEMCASTADDR="234.5.6"
 FRISEBEEMCASTPORT=3564
@@ -241,4 +256,3 @@ FRISEBEEMCASTPORT=3564
 # Sometimes the main page is down in a directory on WWWHOST
 # No trailing '/'!
 #WWW=www.example.emulab.net/emulab-www
-
diff --git a/defs-example-privatecnet b/defs-example-privatecnet
index cd905a178c..f8561cec2d 100644
--- a/defs-example-privatecnet
+++ b/defs-example-privatecnet
@@ -237,6 +237,22 @@ VIRTNODE_NETMASK=255.240.0.0
 JAILIPBASE=$VIRTNODE_NETWORK
 JAILIPMASK=$VIRTNODE_NETMASK
 
+#
+# Only supported on the Mother Ship (emulab.net) right now.
+#
+WIKISUPPORT=0
+BUGDBSUPPORT=0
+MAILMANSUPPORT=0
+CVSSUPPORT=0
+CHATSUPPORT=0
+NFSTRACESUPPORT=0
+ARCHIVESUPPORT=0
+OPSDBSUPPORT=0
+SFSSUPPORT=0
+PELABSUPPORT=0
+PLABSUPPORT=0
+PLAB_ROOTBALL="plabroot-18.tar.bz2"
+
 #
 # You shouldn't have to change anything below this point
 #
@@ -245,7 +261,6 @@ TBADMINGROUP=tbadmin
 TBDBNAME=tbdb
 IPBASE=10
 DELAYCAPACITY=2
-SFSSUPPORT=0
 DISABLE_NSE=1
 FRISEBEEMCASTADDR="234.5.6"
 FRISEBEEMCASTPORT=3564
@@ -253,4 +268,3 @@ FRISEBEEMCASTPORT=3564
 # Sometimes the main page is down in a directory on WWWHOST
 # No trailing '/'!
 #WWW=www.example.emulab.net/emulab-www
-
diff --git a/pelab/GNUmakefile.in b/pelab/GNUmakefile.in
index 8ad7205dac..90f1105838 100644
--- a/pelab/GNUmakefile.in
+++ b/pelab/GNUmakefile.in
@@ -17,4 +17,17 @@ all: $(BIN_STUFF)
 
 include $(TESTBED_SRCDIR)/GNUmakerules
 
-control-install: $(addprefix $(INSTALL_BINDIR)/, $(BIN_STUFF))
+install: subdir-install $(addprefix $(INSTALL_DIR)/opsdir/bin/, $(BIN_STUFF))
+
+boss-install: install
+
+subdir-install:
+	@$(MAKE) -C db boss-install
+	@$(MAKE) -C bgmon boss-install
+
+clean:
+
+$(INSTALL_DIR)/opsdir/bin/%: %
+	@echo "Installing $<"
+	-mkdir -p $(INSTALL_DIR)/opsdir/bin
+	$(INSTALL) $< $@
diff --git a/pelab/bgmon/GNUmakefile.in b/pelab/bgmon/GNUmakefile.in
new file mode 100644
index 0000000000..450a81d400
--- /dev/null
+++ b/pelab/bgmon/GNUmakefile.in
@@ -0,0 +1,31 @@
+#
+# EMULAB-COPYRIGHT
+# Copyright (c) 2006 University of Utah and the Flux Group.
+# All rights reserved.
+#
+
+SRCDIR		= @srcdir@
+TESTBED_SRCDIR	= @top_srcdir@
+OBJDIR		= ../..
+SUBDIR		= pelab/bgmon
+
+USERSBIN_STUFF	= opsrecv.pl manager.pl automanagerclient.pl
+
+include $(OBJDIR)/Makeconf
+
+all: $(USERSBIN_STUFF)
+
+include $(TESTBED_SRCDIR)/GNUmakerules
+
+control-install: $(addprefix $(INSTALL_SBINDIR)/, $(USERSBIN_STUFF))
+
+install: $(addprefix $(INSTALL_DIR)/opsdir/sbin/, $(USERSBIN_STUFF))
+
+boss-install: install
+
+clean:
+
+$(INSTALL_DIR)/opsdir/sbin/%: %
+	@echo "Installing $<"
+	-mkdir -p $(INSTALL_DIR)/opsdir/sbin
+	$(INSTALL) $< $@
diff --git a/rc.d/GNUmakefile.in b/rc.d/GNUmakefile.in
index dd70bf1cf9..2dd155e0cc 100644
--- a/rc.d/GNUmakefile.in
+++ b/rc.d/GNUmakefile.in
@@ -11,6 +11,7 @@ OBJDIR		= ..
 SUBDIR		= rc.d
 
 WINSUPPORT      = @WINSUPPORT@
+PELABSUPPORT    = @PELABSUPPORT@
 SYSTEM         := $(shell uname -s)
 
 include $(OBJDIR)/Makeconf
@@ -30,6 +31,9 @@ else
 RC_SCRIPTS  += 1.named.sh
 endif
 endif
+ifeq ($(WINSUPPORT),1)
+OPS_SCRIPTS += pelab.sh
+endif
 
 #
 # Force dependencies to make sure configure regenerates if the .in file
diff --git a/rc.d/pelab.sh.in b/rc.d/pelab.sh.in
new file mode 100644
index 0000000000..cc9b8cd5f1
--- /dev/null
+++ b/rc.d/pelab.sh.in
@@ -0,0 +1,53 @@
+#!/bin/sh
+#
+# Utah Network Testbed Flexlab (aka PELAB) startup
+#
+
+# XXX config me
+PE_PID=tbres
+PE_EID=pelabbgmon
+
+BINDIR="@prefix@/sbin"
+ETCDIR="@prefix@/etc"
+LOGDIR="@prefix@/log/pelab"
+
+opsrecv_args="-e $PE_PID/$PE_EID -d1"
+manager_args=""
+automanagerclient_args="-l600 0.10"
+
+case "$1" in
+    start)
+	if [ -x $BINDIR/opsrecv.pl -a -r $ETCDIR/pelabdb.pwd ]; then
+	    if [ ! -d $LOGDIR ]; then
+		mkdir -m 755 $LOGDIR
+	    fi
+	    if [ -x $BINDIR/daemon_wrapper ]; then
+		$BINDIR/daemon_wrapper -n opsrecv -l $LOGDIR/opsrecv.log -- \
+			$BINDIR/opsrecv.pl $opsrecv_args
+		$BINDIR/daemon_wrapper -n manager -l $LOGDIR/manager.log -- \
+			$BINDIR/manager.pl $manager_args
+		$BINDIR/daemon_wrapper -n automanagerclient -l $LOGDIR/automanagerclient.log -- \
+	                $BINDIR/automanagerclient.pl $automanagerclient_args
+	    else
+	        $BINDIR/opsrecv.pl $opsrecv_args >$LOGDIR/opsrecv.log 2>&1 &
+	        $BINDIR/manager.pl $manager_args >$LOGDIR/manager.log 2>&1 &
+	        $BINDIR/automanagerclient.pl $automanagerclient_args >$LOGDIR/automanagerclient.log 2>&1 &
+	    fi
+	fi
+		;;
+    stop)
+	if [ -r /var/run/opsrecv_wrapper.pid ]; then
+	    kill `cat /var/run/opsrecv_wrapper.pid`
+	    kill `cat /var/run/manager_wrapper.pid`
+	    kill `cat /var/run/automanagerclient_wrapper.pid`
+	else
+	    pkill -f "perl.*$BINDIR/daemon_wrapper.*(automanagerclient|manager|opsrecv)\.pl"
+        fi
+	;;
+    *)
+	echo ""
+	echo "Usage: `basename $0` { start | stop }"
+	echo ""
+	exit 64
+	;;
+esac
diff --git a/utils/GNUmakefile.in b/utils/GNUmakefile.in
index 7644201b85..84c465cee0 100644
--- a/utils/GNUmakefile.in
+++ b/utils/GNUmakefile.in
@@ -25,7 +25,7 @@ SBIN_SCRIPTS	= vlandiff vlansync withadminprivs export_tables cvsupd.pl \
 LIBEXEC_SCRIPTS	= webcreateimage newnode webdeletenode spewleds webcopy \
                   websetdest spewsource weblinkmon_ctl webcvsweb \
 		  webspewconlog xlogin webviewvc spewevents
-CTRLSBIN_SCRIPTS= opsdb_control.proxy
+CTRLSBIN_SCRIPTS= opsdb_control.proxy daemon_wrapper
 
 # These scripts installed setuid, with sudo. 
 SETUID_BIN_SCRIPTS   = 
diff --git a/utils/daemon_wrapper.in b/utils/daemon_wrapper.in
index 2e313b755a..456f5812b2 100644
--- a/utils/daemon_wrapper.in
+++ b/utils/daemon_wrapper.in
@@ -10,10 +10,10 @@ use POSIX qw(setsid);
 
 sub usage()
 {
-    print "Usage: daemon_wrapper [-i interval] [-p pidfile] [-l logfile] command args ...\n";
+    print STDERR "Usage: daemon_wrapper [-i interval] [-p pidfile] [-l logfile] [-n name] command args ...\n";
     exit(1);
 }
-my $optlist  = "di:p:l:";
+my $optlist  = "di:p:l:n:";
 my $debug    = 0;
 my $mininterval = 1;
 my $maxinterval = (24 * 60 * 60);
@@ -53,12 +53,25 @@ if (defined($options{"p"})) {
 if (defined($options{"l"})) {
     $logfile = $options{"l"};
 }
+if (defined($options{"n"})) {
+    if ($options{"n"} =~ /^([-\w]+)$/) {
+	$daemon = $1;
+    } else {
+	print STDERR "Bogus characters in name string\n";
+	exit(1);
+    }
+    
+}
 if (@ARGV < 1) {
     usage();
 }
 $cmd = shift;
-if ($cmd =~ /.*\/([^\/]+)/) {
-    $daemon = $1;
+if (!defined($daemon)) {
+    if ($cmd =~ /.*\/([-\w]+)$/) {
+	$daemon = $1;
+    } else {
+	$daemon = "pid$$";
+    }
 }
 $cmdargs = join(' ', @ARGV);
 
-- 
GitLab