summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Garbutt <john.garbutt@rackspace.com>2013-06-13 18:31:14 +0100
committerGerrit Code Review <review@openstack.org>2013-06-19 14:41:43 +0000
commit0af9b83a6b2577b45e580e24efe82b692f9d1f05 (patch)
tree68adf2cb7badf251959453af63cbf341f1b0a5f8
parent6808e052dbe9bc51b5836814d0a0331dcc5a6bd2 (diff)
downloadnova-0af9b83a6b2577b45e580e24efe82b692f9d1f05.tar.gz
nova-0af9b83a6b2577b45e580e24efe82b692f9d1f05.tar.xz
nova-0af9b83a6b2577b45e580e24efe82b692f9d1f05.zip
xenapi: script to rotate the guest logs
Xen will produce the guest logs in a specified directory. This scripts configures the above logging as expected by the xapi plugin nova uses to read the logs. In addition it ensures that any log that grows bigger than 1MB will be truncated down to 5KB. Ensuring the log directory is inside a loop back device of a restricted size, and running this script every minute using cron, will stop guests from using up too much Dom0 disk space, and taking out the hypervisor Part of blueprint xenapi-server-log Change-Id: I4caa82f4d0620d924e37e3b605cf62b4d5b73570
-rwxr-xr-xtools/xenserver/rotate_xen_guest_logs.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/tools/xenserver/rotate_xen_guest_logs.sh b/tools/xenserver/rotate_xen_guest_logs.sh
new file mode 100755
index 000000000..0e6c7d6ea
--- /dev/null
+++ b/tools/xenserver/rotate_xen_guest_logs.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+set -eux
+
+# Script to rotate console logs
+#
+# Should be run on Dom0, with cron, every minute:
+# * * * * * /root/rotate_xen_guest_logs.sh
+#
+# Should clear out the guest logs on every boot
+# because the domain ids may get re-used for a
+# different tenant after the reboot
+#
+# /var/log/xen/guest should be mounted into a
+# small loopback device to stop any guest being
+# able to fill dom0 file system
+
+log_dir="/var/log/xen/guest"
+kb=1024
+max_size_bytes=$(($kb*$kb))
+truncated_size_bytes=$((5*$kb))
+list_domains=/opt/xensource/bin/list_domains
+
+log_file_base="${log_dir}/console."
+tmp_file_base="${log_dir}/tmp.console."
+
+# Ensure logging is setup correctly for all domains
+xenstore-write /local/logconsole/@ "${log_file_base}%d"
+
+# Move logs we want to keep
+domains=$($list_domains | sed '/^id*/d' | sed 's/|.*|.*$//g' | xargs)
+for i in $domains; do
+ log="${log_file_base}$i"
+ tmp="${tmp_file_base}$i"
+ mv $log $tmp || true
+done
+
+# Delete all console logs,
+# mostly to remove logs from recently killed domains
+rm -f ${log_dir}/console.*
+
+# Reload domain list, in case it changed
+# (note we may have just deleted a new console log)
+domains=$($list_domains | sed '/^id*/d' | sed 's/|.*|.*$//g' | xargs)
+for i in $domains; do
+ log="${log_file_base}$i"
+ tmp="${tmp_file_base}$i"
+ size=$(stat -c%s "$tmp")
+
+ # Trim the log if required
+ if [ "$size" -gt "$max_size_bytes" ]; then
+ tail -c $truncated_size_bytes $tmp > $log || true
+ else
+ mv $tmp $log || true
+ fi
+
+ # Notify xen that it needs to reload the file
+ xenstore-write /local/logconsole/$i $log
+ xenstore-rm /local/logconsole/$i
+done
+
+# Delete all the tmp files
+rm -f ${tmp_file_base}* || true