iterate
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 14 Jan 2010 12:12:54 +0000 (12:12 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 14 Jan 2010 12:12:54 +0000 (12:12 +0000)
Makefile
README
bootmanager.spec
build.sh
nodeconfig/boot/index.php
nodeconfig/boot/upload-bmlog.php [new file with mode: 0755]
support-files/desc [deleted file]
support-files/uudecode.gz [deleted file]

index 7769042..e427288 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -42,6 +42,6 @@ endif
 
 ##########
 tags:
-       find . '(' -name '*.py' -o -name '*.spec' ')' | xargs etags
+       find . -type f | egrep -v '/\.svn/|~$$' | xargs etags
 
 .PHONY: tags
diff --git a/README b/README
index 09a756f..262af5d 100644 (file)
--- a/README
+++ b/README
@@ -5,8 +5,8 @@ the entry point for the boot CD is installed in
     /var/www/html/boot/index.php
 the bootmanager rpm installs most of its stuff in 
     /usr/share/bootmanager/regular/
-all signed scripts are stored into 
-    /var/www/html/bootmanager
+and the default signed script is created as
+    /var/www/html/boot/bootmanager_regular.sh.sgn
 
 ===
 If you need to create an alternate version for a specific 'deployment'
@@ -27,4 +27,4 @@ which should do everything needed
 
 ===
 It's also possible to attach a (signed) bm script to a unique node by renaming a .sgn into
-/var/www/html/bootmanager/<hostname>_bootmanager.sh.sgn
+/var/www/html/boot/bootmanager_<hostname>.sh.sgn
index 1a3cff3..0ef34e5 100644 (file)
@@ -29,9 +29,10 @@ Requires: PLCAPI >= 4.3
 # the python code packaged in these are shipped on the node as well
 Requires: pypcilib pyplnet monitor-runlevelagent
 
-# plc.d/bootmanager is moving
+### avoid having yum complain about updates, as stuff is moving around
+# plc.d/bootmanager
 Conflicts: myplc <= 4.3-37
-# nodeconfig/boot/index.php is moving
+# nodeconfig/boot/*
 Conflicts: nodeconfig <= 4.3-7
 
 AutoReqProv: no
@@ -57,15 +58,17 @@ install -m 644 README  $RPM_BUILD_ROOT/%{_datadir}/%{name}/README
 
 # formerly in the nodeconfig module
 install -D -m 755 nodeconfig/boot/index.php $RPM_BUILD_ROOT/var/www/html/boot/index.php
+install -D -m 755 nodeconfig/boot/upload-bmlog.php $RPM_BUILD_ROOT/var/www/html/boot/upload-bmlog.php
 
 # formerly in the MyPLC module
-install -D -m 755 plc.d/bootmanager $RPM_BUILD_ROOT/etc/pld.c/bootmanager
+install -D -m 755 plc.d/bootmanager $RPM_BUILD_ROOT/etc/plc.d/bootmanager
 
 %clean
 rm -rf $RPM_BUILD_ROOT
 
 %post
-# signing of botmanager.sh occurs as part of plc.d/bootmanager
+# signing of botmanager.sh occurs as part of /etc/plc.d/bootmanager
+# which in turn invokes build.sh
 
 # NOTE: do not run this agent when installed on a myplc.
 # xxx - a bit hacky maybe
@@ -76,7 +79,7 @@ chkconfig --del monitor-runlevelagent
 %defattr(-,root,root,-)
 %{_datadir}/%{name}
 /var/www/html/boot/index.php
-/etc/pld.c/bootmanager
+/etc/plc.d/bootmanager
 
 %changelog
 * Sat Jan 09 2010 Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr> - BootManager-4.3-16
index 6362ca6..06e9f00 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -32,15 +32,15 @@ cd $(dirname $0)
 sed -i -e "s|SUPPORT_FILE_DIR=.*|SUPPORT_FILE_DIR=$BOOTSTRAPDIR|" source/configuration
 
 # Source bootmanager configuration
-. $srcdir/source/configuration
+. source/configuration
 
 # Write boot script. nodeconfig/boot/index.php retrieves the contents of this script
 # after checking the node id
 
-BMDIR=/var/www/html/bootmanager
+BMDIR=/var/www/html/boot
 mkdir -p $BMDIR
 
-DEST_SCRIPT="$BMDIR/${DEPLOYMENT}_bootmanager.sh"
+DEST_SCRIPT="$BMDIR/bootmanager_${DEPLOYMENT}.sh"
 # Remove the old version or any sym links prior to re-writing
 rm -f ${DEST_SCRIPT}
 rm -f ${DEST_SCRIPT}.sgn
@@ -88,14 +88,12 @@ cat <<EOF > $DEST_SCRIPT
 # Do not tolerate errors
 set -e
 
-UUDECODE=/usr/bin/uudecode
-
-($UUDECODE | /bin/tar -C /tmp -xj) << _EOF_
+(/usr/bin/uudecode | /bin/tar -C /tmp -xj) << _EOF_
 EOF
 
 
 # Embed the uuencoded tarball in the script
-tar -cj -C $srcdir source/ -C $extra_libs source/ | uuencode -m - >> $DEST_SCRIPT
+tar -cj source/ -C $extra_libs source/ | uuencode -m - >> $DEST_SCRIPT
 
 # wrap up the script
 echo '_EOF_' >> $DEST_SCRIPT
index 81ec490..fc64e3d 100755 (executable)
@@ -13,10 +13,10 @@ require_once 'plc_api.php';
 global $adm;
 
 // location for signed scripts
-$bmdir="/var/www/html/bootmanager";
+$bmdir="/var/www/html/boot";
+$bmext=".sh.sgn";
 
-// Default bootmanager
-$bootmanager = "bootmanager.sh.sgn";
+$candidates = array();
 
 // Look up the node
 $interfaces = $adm->GetInterfaces(array('ip' => $_SERVER['REMOTE_ADDR']));
@@ -58,23 +58,20 @@ if (isset($node)) {
 
   // Custom bootmanager for the node, e.g.
   // planetlab-1.cs.princeton.edu_bootmanager.sh.sgn
-  $bootmanagers = array(strtolower($node['hostname']) . "_" . $bootmanager);
+  $candidates [] = "bootmanager" . "_" . strtolower($node['hostname']);
 
   // Custom bootmanager for the deployment tag, e.g.
-
-  if (!empty($node['nodegroup_ids'])) {
-    $nodegroups = $adm->GetNodeDeployment($node['nodegroup_ids']);
-    foreach ($nodegroups as $nodegroup) {
-      $bootmanagers[] = strtolower($nodegroup['groupname']) . "_" . $bootmanager;
-    }
+  $deployment = $adm->GetNodeDeployment($node['node_id']);
+  if ( ! empty ($deployment) ) {
+    $candidates[] = "bootmanager" . "_" . $deployment;
   }
 }
 
 // Default bootmanager
-$bootmanagers[] = "regular_" . $bootmanager;
+$candidates[] = "bootmanager_regular";
 
-foreach ($bootmanagers as $bootmanager) {
-  $candidate=$bmdir . "/" . $bootmanager;
+foreach ($candidates as $bootmanager) {
+  $candidate=$bmdir . "/" . $bootmanager . $bmext ;
   if (file_exists($candidate)) {
     readfile($candidate);
     exit();
diff --git a/nodeconfig/boot/upload-bmlog.php b/nodeconfig/boot/upload-bmlog.php
new file mode 100755 (executable)
index 0000000..6e29e23
--- /dev/null
@@ -0,0 +1,112 @@
+<?php
+
+// Thierry Parmentelat -- INRIA
+// first draft for a revival of former (3.x?) alpina-logs in 5.0
+
+// this needs be created with proper permissions at package install time
+$logdir="/var/log/bm";
+
+// limit: applies to uploads coming from an unrecognized IP
+$limit_bytes=4*1024;
+
+$default_hostname="unknown";
+
+function mkdir_if_needed ($dirname) {
+  if (is_dir ($dirname))
+    return;
+  mkdir ($dirname) or die ("Cannot create dir " . $dirname);
+}
+  
+// Get admin API handle
+require_once 'plc_api.php';
+global $adm;
+
+// find the node that these longs should belong to by looking for a node_id
+// with an ip the same as the http requestor ip
+$ip = $_SERVER['REMOTE_ADDR'];
+
+$hostname=$default_hostname;
+// locate hostname from DB based on this IP
+$interfaces=$adm->GetInterfaces(array("ip"=>$ip));
+if (! empty($interfaces) ) {
+  $interface=$interfaces[0];
+  $node_id=$interface['node_id'];
+  $nodes=$adm->GetNodes($node_id,array("hostname"));
+  if (!empty($nodes)) {
+    $hostname=$nodes[0]['hostname'];
+  }
+ }
+
+// store the actual data in /var/log/bm/raw/2008-11-31-20-02-onelab01.inria.fr-138.96.250.141.txt
+
+$rawdir=$logdir . "/raw";
+$date=strftime("%Y-%m-%d-%H-%M");
+$log_name=$date . "-" . $hostname . "-" . $ip . ".txt";
+$log_path=$rawdir . "/" . $log_name;
+$month=strftime("%Y-%m");
+$time=strftime("%d-%H-%M");
+
+mkdir_if_needed ($rawdir);
+
+////////////////////////////////////////
+
+$log=fopen($log_path,"w") or die ("Cannot open logfile "+$log_path);
+
+$uploaded_name= $_FILES['log']['tmp_name'];
+$uploaded_size=filesize($uploaded_name);
+
+fprintf ($log, "BootManager log created on: %s-%s\n",$month,$time);
+fprintf( $log, "From IP: %s\n",$ip);
+fprintf( $log, "hostname: %s\n",$hostname);
+fprintf ( $log, "uploaded file: %s (%d bytes)\n",$uploaded_name,$uploaded_size);
+if ( ( strcmp($hostname,$default_hostname)==0) && ( $uploaded_size >= $limit_bytes) ) {
+  fprintf ( $log, "contents from an unrecognized IP address was truncated to %d bytes\n",$limit_bytes);
+  $truncated=TRUE;
+  $uploaded_size=$limit_bytes;
+ } else {
+  $truncated=FALSE;
+ }
+
+fprintf( $log, "-----------------\n\n" );
+$uploaded = fopen($uploaded_name,'r');
+$contents = fread($uploaded, $uploaded_size);
+fclose($uploaded);
+fwrite($log,$contents);
+if ($truncated)
+  fwrite ($log, " ..<" . "truncated" . ">..\n");
+fclose($log);
+
+////////////////////////////////////////
+
+// create symlinks for easy browsing
+
+// /var/log/bm/per-month/2008-11/onelab1.inria.fr/31-20-02.bmlog
+$linkdir=$logdir;
+$linkdir=$linkdir . "/per-month";
+mkdir_if_needed ($linkdir);
+$linkdir=$linkdir . "/" . $month;
+mkdir_if_needed ($linkdir);
+$linkdir = $linkdir . "/" . $hostname;
+mkdir_if_needed ($linkdir);
+$link = $linkdir . "/" . $time ;
+symlink ("../../../raw/".$log_name,$link);
+
+# /var/log/bm/per-hostname/onelab1.inria.fr/2008-11-31-20-02.bmlog
+$linkdir=$logdir;
+$linkdir=$linkdir . "/per-hostname";
+mkdir_if_needed ($linkdir);
+$linkdir=$linkdir . "/" . $hostname;
+mkdir_if_needed ($linkdir);
+$link = $linkdir . "/" . $month . "-" . $time ;
+symlink ("../../raw/".$log_name,$link);
+
+# /var/log/bm/per-ip/138.96.250.141/2008-11-31-20-02.bmlog
+$linkdir=$logdir;
+$linkdir=$linkdir . "/per-ip";
+mkdir_if_needed ($linkdir);
+$linkdir=$linkdir . "/" . $ip;
+mkdir_if_needed ($linkdir);
+$link = $linkdir . "/" . $month . "-" . $time ;
+symlink ("../../raw/".$log_name,$link);
+
+?>
diff --git a/support-files/desc b/support-files/desc
deleted file mode 100644 (file)
index c19c2a3..0000000
+++ /dev/null
@@ -1 +0,0 @@
-The BuildSupport directory is used to build tarballs of files necessary during the install, including files to bootstrap RPM, handle booting off of lvm volumes, and partitioning disks.
diff --git a/support-files/uudecode.gz b/support-files/uudecode.gz
deleted file mode 100755 (executable)
index 040c34f..0000000
Binary files a/support-files/uudecode.gz and /dev/null differ