Index: package_tags/sipb-xen-console-server/2.8/debian/changelog
===================================================================
--- package_tags/sipb-xen-console-server/2.8/debian/changelog	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/debian/changelog	(revision 1122)
@@ -0,0 +1,99 @@
+sipb-xen-console-server (2.8) unstable; urgency=low
+
+  * Create a dummy console entry that exists by default so that conserver
+    won't quit if no consoles are defined.
+
+ -- Evan Broder <broder@mit.edu>  Tue, 14 Oct 2008 03:10:28 -0400
+
+sipb-xen-console-server (2.7) unstable; urgency=low
+
+  * Don't run conserver as root; use sudo instead
+
+ -- Evan Broder <broder@mit.edu>  Tue, 14 Oct 2008 02:38:46 -0400
+
+sipb-xen-console-server (2.06.3) unstable; urgency=low
+
+  * Running conserver as root so it can run xm console
+
+ -- Evan Broder <broder@mit.edu>  Tue, 14 Oct 2008 01:42:26 -0400
+
+sipb-xen-console-server (2.06.2) unstable; urgency=low
+
+  * No really - correctly divert conserver.cf
+
+ -- Evan Broder <broder@mit.edu>  Tue, 14 Oct 2008 01:39:09 -0400
+
+sipb-xen-console-server (2.06.1) unstable; urgency=low
+
+  * Correctly divert conserver.cf
+
+ -- Evan Broder <broder@mit.edu>  Tue, 14 Oct 2008 01:34:25 -0400
+
+sipb-xen-console-server (2.06) unstable; urgency=low
+
+  * generate config files using mako
+
+ -- Yang Zhang <y_z@mit.edu>  Thu, 14 Aug 2008 15:15:18 -0400
+
+sipb-xen-console-server (2.05) unstable; urgency=low
+
+  * use invirt.config rather than /etc/invirt/* directly
+  * get console-server hostname, db connection string from config
+  * generate conserver config piece needing console-server ip
+  * remove console 's_sipb-xen-dev', which doesn't work anyway
+  * all configured!
+
+ -- Greg Price <price@mit.edu>  Sat,  2 Aug 2008 18:58:59 -0400
+
+sipb-xen-console-server (2.04) unstable; urgency=low
+
+  * Get Kerberos realm from config rather than hardcoding.
+  * Don't hardcode host's hostname in conserver.cf.
+  * Update for current config-package-dev.
+
+ -- Greg Price <price@mit.edu>  Tue, 22 Jul 2008 01:32:04 -0400
+
+sipb-xen-console-server (2.03) unstable; urgency=low
+
+  * Multiplex consoles on multiple hosts.
+
+ -- Greg Price <price@mit.edu>  Sun, 13 Jul 2008 08:35:17 -0400
+
+sipb-xen-console-server (2.02) unstable; urgency=low
+
+  * And...xm isn't in the path, so give a full path
+
+ -- Evan Broder <broder@sipb-xen-dev.mit.edu>  Wed,  2 Apr 2008 04:48:53 -0400
+
+sipb-xen-console-server (2.01) unstable; urgency=low
+
+  * update-conserver script should reload, not restart
+
+ -- Evan Broder <broder@sipb-xen-dev.mit.edu>  Wed,  2 Apr 2008 04:43:12 -0400
+
+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
+
+ -- Evan Broder <broder@sipb-xen-dev.mit.edu>  Wed,  2 Apr 2008 01:41:32 -0400
+
+sipb-xen-console-server (1.0.1) unstable; urgency=low
+
+  * Misnamed a file
+
+ -- Evan Broder <broder@sipb-xen-dev.mit.edu>  Wed,  2 Apr 2008 01:36:29 -0400
+
+sipb-xen-console-server (1) unstable; urgency=low
+
+  * Initial release.
+
+ -- SIPB Xen Project <sipb-xen@mit.edu>  Wed,  2 Apr 2008 00:27:12 -0400
Index: package_tags/sipb-xen-console-server/2.8/debian/compat
===================================================================
--- package_tags/sipb-xen-console-server/2.8/debian/compat	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/debian/compat	(revision 1122)
@@ -0,0 +1,1 @@
+5
Index: package_tags/sipb-xen-console-server/2.8/debian/control
===================================================================
--- package_tags/sipb-xen-console-server/2.8/debian/control	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/debian/control	(revision 1122)
@@ -0,0 +1,14 @@
+Source: sipb-xen-console-server
+Section: servers
+Priority: important
+Maintainer: sipb-xen@mit.edu
+Build-Depends: cdbs (>= 0.4.23-1.1), debhelper (>= 5), config-package-dev (>= 4.5~)
+Standards-Version: 3.7.2
+
+Package: sipb-xen-console-server
+Architecture: all
+Provides: ${diverted-files}
+Conflicts: ${diverted-files}
+Depends: ${shlibs:Depends}, ${misc:Depends}, conserver-server, remctl-client
+Description: SIPB Xen serial console server server
+  This configures the VMM for the server-side of the console server
Index: package_tags/sipb-xen-console-server/2.8/debian/control.in
===================================================================
--- package_tags/sipb-xen-console-server/2.8/debian/control.in	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/debian/control.in	(revision 1122)
@@ -0,0 +1,14 @@
+Source: sipb-xen-console-server
+Section: servers
+Priority: important
+Maintainer: sipb-xen@mit.edu
+Build-Depends: @cdbs@
+Standards-Version: 3.7.2
+
+Package: sipb-xen-console-server
+Architecture: all
+Provides: ${diverted-files}
+Conflicts: ${diverted-files}
+Depends: ${shlibs:Depends}, ${misc:Depends}, conserver-server, remctl-client
+Description: SIPB Xen serial console server server
+  This configures the VMM for the server-side of the console server
Index: package_tags/sipb-xen-console-server/2.8/debian/copyright
===================================================================
--- package_tags/sipb-xen-console-server/2.8/debian/copyright	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/debian/copyright	(revision 1122)
@@ -0,0 +1,3 @@
+This package was created for internal use of the SIPB Xen Project of
+the MIT Student Information Processing Board.  Ask sipb-xen@mit.edu if
+you have questions about redistribution.
Index: package_tags/sipb-xen-console-server/2.8/debian/rules
===================================================================
--- package_tags/sipb-xen-console-server/2.8/debian/rules	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/debian/rules	(revision 1122)
@@ -0,0 +1,10 @@
+#!/usr/bin/make -f
+
+DEB_AUTO_UPDATE_DEBIAN_CONTROL = 1
+DEB_DIVERT_EXTENSION = .sipb-xen
+DEB_DIVERT_FILES_sipb-xen-console-server += \
+	/etc/conserver/conserver.cf.sipb-xen \
+	/etc/conserver/server.conf.sipb-xen
+
+include /usr/share/cdbs/1/rules/debhelper.mk
+include /usr/share/cdbs/1/rules/config-package.mk
Index: package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.cron.d
===================================================================
--- package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.cron.d	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.cron.d	(revision 1122)
@@ -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: package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.init
===================================================================
--- package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.init	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.init	(revision 1122)
@@ -0,0 +1,112 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          sipb-xen-console-server
+# Required-Start:    $local_fs $remote_fs
+# Required-Stop:     $local_fs $remote_fs
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: conserver config from invirt config for invirt host
+# Description:       
+### END INIT INFO
+
+# Author: Invirt/XVM Project, MIT SIPB <invirt@mit.edu>
+
+# Do NOT "set -e"
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="Invirt host console config"
+NAME=sipb-xen-console-server
+SCRIPTNAME=/etc/init.d/$NAME
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
+. /lib/lsb/init-functions
+
+gen_config()
+{
+        for i in /etc/conserver/invirt-genconfig.cf
+        do mako-render $i.mako > $i
+        done
+}
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+	# Return
+	#   0 if daemon has been started
+	#   1 if daemon was already running
+	#   2 if daemon could not be started
+	gen_config
+	VERBOSE=no /etc/init.d/conserver-server reload
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+	return 1
+}
+
+do_reload()
+{
+	gen_config
+	VERBOSE=no /etc/init.d/conserver-server reload
+}
+
+case "$1" in
+  start)
+	[ "$VERBOSE" != no ] && log_begin_msg "Starting $DESC" "$NAME"
+	do_start
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  stop)
+	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+	do_stop
+	case "$?" in
+		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+	esac
+	;;
+  reload|force-reload)
+	log_daemon_msg "Reloading $DESC" "$NAME"
+	do_reload
+	log_end_msg $?
+	;;
+  restart)
+	log_daemon_msg "Restarting $DESC" "$NAME"
+	do_stop
+	case "$?" in
+	  0|1)
+		do_start
+		case "$?" in
+			0) log_end_msg 0 ;;
+			1) log_end_msg 1 ;; # Old process is still running
+			*) log_end_msg 1 ;; # Failed to start
+		esac
+		;;
+	  *)
+	  	# Failed to stop
+		log_end_msg 1
+		;;
+	esac
+	;;
+  *)
+	echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
+	exit 3
+	;;
+esac
+
+:
Index: package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.install
===================================================================
--- package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.install	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.install	(revision 1122)
@@ -0,0 +1,1 @@
+files/* .
Index: package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.postinst
===================================================================
--- package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.postinst	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.postinst	(revision 1122)
@@ -0,0 +1,44 @@
+#!/bin/sh
+# postinst script for sipb-xen-console-server
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <postinst> `configure' <most-recently-configured-version>
+#        * <old-postinst> `abort-upgrade' <new version>
+#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+#          <new-version>
+#        * <postinst> `abort-remove'
+#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+#          <failed-install-package> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+case "$1" in
+    configure)
+        cat >>/etc/sudoers <<EOF
+### BEGIN sipb-xen-console-server
+conservr ALL=(ALL) NOPASSWD: /usr/sbin/xm console d_*
+### END sipb-xen-console-server
+EOF
+    ;;
+
+    abort-upgrade|abort-remove|abort-deconfigure)
+    ;;
+
+    *)
+        echo "postinst called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
Index: package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.prerm
===================================================================
--- package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.prerm	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/debian/sipb-xen-console-server.prerm	(revision 1122)
@@ -0,0 +1,39 @@
+#!/bin/sh
+# prerm script for sipb-xen-console-server
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <prerm> `remove'
+#        * <old-prerm> `upgrade' <new-version>
+#        * <new-prerm> `failed-upgrade' <old-version>
+#        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
+#        * <deconfigured's-prerm> `deconfigure' `in-favour'
+#          <package-being-installed> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+
+
+case "$1" in
+    remove|upgrade|deconfigure)
+        perl -i.bak -ne 's%^### (BEGIN|END) sipb-xen-console-server\s*$%%m && ($skip = ($1 eq "BEGIN")); print unless $skip;' /etc/sudoers
+    ;;
+
+    failed-upgrade)
+    ;;
+
+    *)
+        echo "prerm called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0
Index: package_tags/sipb-xen-console-server/2.8/files/etc/conserver/conserver.cf.sipb-xen
===================================================================
--- package_tags/sipb-xen-console-server/2.8/files/etc/conserver/conserver.cf.sipb-xen	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/files/etc/conserver/conserver.cf.sipb-xen	(revision 1122)
@@ -0,0 +1,25 @@
+config * {
+	sslrequired yes;
+}
+
+# If no consoles are defined, as is the case when the host first boots
+# up, conserver will quit. This keeps it running.
+#
+# Should someone create a VM called dummy-console, their VM will
+# shadow over this one.
+console dummy-console {
+        master localhost;
+        type noop;
+}
+
+default * {
+	logfile /var/log/conserver/&.log;
+	timestamp "1lab";
+	rw *;
+	type exec;
+	exec sudo xm console d_f;
+	execsubst f=cs;
+}
+
+#include /etc/conserver/invirt-genconfig.cf
+#include /etc/conserver/sipb-xen-consoles.cf
Index: package_tags/sipb-xen-console-server/2.8/files/etc/conserver/invirt-genconfig.cf.mako
===================================================================
--- package_tags/sipb-xen-console-server/2.8/files/etc/conserver/invirt-genconfig.cf.mako	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/files/etc/conserver/invirt-genconfig.cf.mako	(revision 1122)
@@ -0,0 +1,6 @@
+<% from invirt.config import structs as cfg %>\
+access * {
+       trusted 127.0.0.1;
+       trusted ${cfg.console.ip};
+       limited *;
+}
Index: package_tags/sipb-xen-console-server/2.8/files/etc/conserver/server.conf.sipb-xen
===================================================================
--- package_tags/sipb-xen-console-server/2.8/files/etc/conserver/server.conf.sipb-xen	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/files/etc/conserver/server.conf.sipb-xen	(revision 1122)
@@ -0,0 +1,2 @@
+OPTS='-p 3109  '
+ASROOT=
Index: package_tags/sipb-xen-console-server/2.8/files/usr/sbin/sipb-xen-update-conserver
===================================================================
--- package_tags/sipb-xen-console-server/2.8/files/usr/sbin/sipb-xen-update-conserver	(revision 1122)
+++ package_tags/sipb-xen-console-server/2.8/files/usr/sbin/sipb-xen-update-conserver	(revision 1122)
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+import sipb_xen_database
+import subprocess
+import os
+import socket
+from invirt.config import structs as config
+
+sipb_xen_database.connect(config.db.uri)
+
+def live_vms():
+    p = subprocess.Popen(['/usr/sbin/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', 'reload'], stdout=subprocess.PIPE)
+    p.wait()
+
+if __name__ == '__main__':
+    hostname = socket.getfqdn().lower()
+    realm = config.authn[0].realm
+    principal = 'host/'+hostname+'@'+realm
+    conftext = '\n'.join('console %s { master %s; }' % (vm, hostname)
+                         for vm in live_vms())
+    f = open('/etc/conserver/sipb-xen-consoles.cf', 'w')
+    f.write(conftext)
+    f.close()
+    reload_conserver()
+    subprocess.call(['/usr/bin/kinit', '-k', '-t', '/etc/krb5.keytab',
+                     principal])
+    subprocess.call(['/usr/bin/remctl', config.console.hostname,
+                     'console', 'update', conftext])
