Add deployment mechanism for hotfixes to nodes in chosen nodegroups.
authorStephen Soltesz <soltesz@cs.princeton.edu>
Tue, 10 May 2011 23:40:38 +0000 (19:40 -0400)
committerStephen Soltesz <soltesz@cs.princeton.edu>
Tue, 10 May 2011 23:40:38 +0000 (19:40 -0400)
PlanetLabConf/hotfixes.php [new file with mode: 0644]
PlanetLabConf/hotfixes/build.sh [new file with mode: 0755]
db-config.d/030-conf_files_hotfixes [new file with mode: 0644]

diff --git a/PlanetLabConf/hotfixes.php b/PlanetLabConf/hotfixes.php
new file mode 100644 (file)
index 0000000..8fdbb7d
--- /dev/null
@@ -0,0 +1,72 @@
+<?php 
+
+/*
+    hotfixes.php -- 
+        The purpose is to provide a mechanism for deploying source fixes 
+        faster than, or instead of, waiting for rpm updates.
+
+        The machanism is via tar files copied from PlanetLabConf/hotfixes/* to
+        the root filesystem of machines in a given nodegroup.
+
+    Notes:
+        Nodes call this script via ConfFiles; the tar file for the first 
+        matching nodegroup is returned to the node.
+*/
+
+require_once 'plc_api.php';
+global $adm;
+if ( isset($_REQUEST['debug']) ) {
+    $debug = true;
+}
+
+function logit($str) 
+{
+    global $debug;
+    if ( $debug == true ) 
+    {
+        print $str . "\n";
+    }
+}
+
+logit("nodeid check");
+$ng_names = array();
+
+if ( isset($_REQUEST['node_id']) ) {
+  logit("getnodes");
+  $nodes = $adm->GetNodes(array(intval($_REQUEST['node_id'])));
+  if (!empty($nodes)) {
+    $node = $nodes[0];
+  } else {
+    exit(1);
+  }
+  if ( count($node['nodegroup_ids']) > 0 )
+  {
+      // collect a list of all nodegroup names for this node.
+      foreach ( $node['nodegroup_ids'] as $ng_id ) {
+        $ngs = $adm->GetNodeGroups(array('nodegroup_id' => $ng_id));
+        if (!empty($ngs)) {
+            logit($ngs[0]['groupname']);
+            $ng_names[] = $ngs[0]['groupname'];
+        }
+      }
+  } else {
+    $ng_names[] = "default";
+  }
+}
+
+foreach ( $ng_names as $name ) 
+{
+    logit("name: " . $name);
+    // check that directory exists
+    $file= "hotfixes/$name.tar";
+    $stat = stat($file);
+    if ( !empty ($stat) )
+    {
+        // send to client
+        readfile($file);
+        // stop after the first match.
+        exit(1);
+    } 
+}
+
+?>
diff --git a/PlanetLabConf/hotfixes/build.sh b/PlanetLabConf/hotfixes/build.sh
new file mode 100755 (executable)
index 0000000..238ef2e
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# Look for all directories in the PlanetLabConf/hotfixes directory and 
+# create tar files for hotfixes on nodegroups with the same name.
+
+for dir in `find . -maxdepth 1 -type d  | grep -vE "^.$"` ; do 
+    b=$dir.tar
+    d=$dir
+    tar -C $d --create --file $b .
+done
diff --git a/db-config.d/030-conf_files_hotfixes b/db-config.d/030-conf_files_hotfixes
new file mode 100644 (file)
index 0000000..69b237b
--- /dev/null
@@ -0,0 +1,20 @@
+#/usr/bin/env plcsh
+
+conf_files = [
+    { 'source': 'PlanetLabConf/hotfixes.php',
+    'dest': '/tmp/hotfixes.tar',
+    'file_owner': 'root',
+    'file_group': 'root'
+    'file_permissions': '644',
+    'enabled': True,
+    'preinstall_cmd': '',
+    'postinstall_cmd': 'tar -C / -xf /tmp/hotfixes.tar',
+    'error_cmd': '',
+    'ignore_cmd_errors': False,
+    'always_update': False},
+ ]
+
+for conf_file in conf_files:
+       SetConfFile(conf_file)
+
+