xenapi: Setup and Rotate text console logs

This patch installs the cronjob that rotates/sets up the text console
logs of the guests.

Related to blueprint xenapi-server-log

Change-Id: Ie4c778b54f69519fbb80aa0d9822383f55a1e2f9
diff --git a/tools/xen/install_os_domU.sh b/tools/xen/install_os_domU.sh
index 6eb3013..2cba33c 100755
--- a/tools/xen/install_os_domU.sh
+++ b/tools/xen/install_os_domU.sh
@@ -63,12 +63,25 @@
 
 ## Nova plugins
 NOVA_ZIPBALL_URL=${NOVA_ZIPBALL_URL:-$(zip_snapshot_location $NOVA_REPO $NOVA_BRANCH)}
-install_xapi_plugins_from_zipball $NOVA_ZIPBALL_URL
+EXTRACTED_NOVA=$(extract_remote_zipball "$NOVA_ZIPBALL_URL")
+install_xapi_plugins_from "$EXTRACTED_NOVA"
+
+LOGROT_SCRIPT=$(find "$EXTRACTED_NOVA" -name "rotate_xen_guest_logs.sh" -print)
+if [ -n "$LOGROT_SCRIPT" ]; then
+    mkdir -p "/var/log/xen/guest"
+    cp "$LOGROT_SCRIPT" /root/consolelogrotate
+    chmod +x /root/consolelogrotate
+    echo "* * * * * /root/consolelogrotate" | crontab
+fi
+
+rm -rf "$EXTRACTED_NOVA"
 
 ## Install the netwrap xapi plugin to support agent control of dom0 networking
 if [[ "$ENABLED_SERVICES" =~ "q-agt" && "$Q_PLUGIN" = "openvswitch" ]]; then
     NEUTRON_ZIPBALL_URL=${NEUTRON_ZIPBALL_URL:-$(zip_snapshot_location $NEUTRON_REPO $NEUTRON_BRANCH)}
-    install_xapi_plugins_from_zipball $NEUTRON_ZIPBALL_URL
+    EXTRACTED_NEUTRON=$(extract_remote_zipball "$NEUTRON_ZIPBALL_URL")
+    install_xapi_plugins_from "$EXTRACTED_NEUTRON"
+    rm -rf "$EXTRACTED_NEUTRON"
 fi
 
 create_directory_for_kernels