Create and destroy conserver consoles through a Python script, sipb-xen-console-server/2
authorEvan Broder <broder@mit.edu>
Wed, 2 Apr 2008 08:36:45 +0000 (04:36 -0400)
committerEvan Broder <broder@mit.edu>
Wed, 2 Apr 2008 08:36:45 +0000 (04:36 -0400)
instead of a shell script. Also run this script every 5 minutes or so

svn path=/trunk/packages/sipb-xen-console-server/; revision=397

debian/changelog
debian/sipb-xen-console-server.cron.d [new file with mode: 0644]
files/etc/conserver/conserver.cf.sipb-xen
files/etc/conserver/sipb-xen-consoles.cf [moved from files/etc/conserver/includes.cf with 100% similarity]
files/usr/sbin/sipb-xen-update-conserver

index 961e457..2b0b531 100644 (file)
@@ -1,3 +1,12 @@
+sipb-xen-console-server (2) unstable; urgency=low
+
+  * Use a python based update-conserver script that gets the list of
+    consoles from xm list
+  * Run the update-conserver script every 5 minutes to catch VMs that
+    are not started or stopped through the remctl interface
+
+ -- Evan Broder <broder@sipb-xen-dev.mit.edu>  Wed,  2 Apr 2008 04:32:58 -0400
+
 sipb-xen-console-server (1.0.2) unstable; urgency=low
 
   * Also...make this package actually do something
diff --git a/debian/sipb-xen-console-server.cron.d b/debian/sipb-xen-console-server.cron.d
new file mode 100644 (file)
index 0000000..1af2beb
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# cron-jobs for sipb-xen-console-server
+# Refresh the list of active VM consoles
+#
+
+MAILTO=root
+
+*/5 * * * * root python /usr/sbin/sipb-xen-update-conserver
index 094685a..b867b6d 100644 (file)
@@ -23,7 +23,7 @@ console s_sipb-xen-dev {
        exec xm console s_sipb-xen-dev;
 }
 
-#include /etc/conserver/includes.cf
+#include /etc/conserver/sipb-xen-consoles.cf
 
 ##
 ## list of clients we allow
index 297fefe..18d0ad8 100755 (executable)
@@ -1,4 +1,24 @@
-#!/bin/bash
+#!/usr/bin/python
 
-ls /etc/conserver/conf.d/ | sed -e 's|^|#include /etc/conserver/conf.d/|' >/etc/conserver/includes.cf
-/etc/init.d/conserver-server reload
\ No newline at end of file
+import sipb_xen_database
+import subprocess
+import os
+
+sipb_xen_database.connect('postgres://sipb-xen@sipb-xen-dev.mit.edu/sipb_xen')
+
+def live_vms():
+    p = subprocess.Popen(['xm', 'list'], stdout=subprocess.PIPE)
+    p.wait()
+    output = p.stdout.read()
+    vms = [x.split()[0][2:] for x in output.splitlines() if x.startswith('d_')]
+    return vms
+
+def reload_conserver():
+    p = subprocess.Popen(['/etc/init.d/conserver-server', 'restart'], stdout=subprocess.PIPE)
+    p.wait()
+
+if __name__ == '__main__':
+    f = open('/etc/conserver/sipb-xen-consoles.cf', 'w')
+    f.write('\n'.join('console %s {}' % vm for vm in live_vms()))
+    f.close()
+    reload_conserver()