debuggers.hg
changeset 17956:20966aa89739
xend: improve the rotation of qemu-dm logfiles.
Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Tue Jul 01 10:58:43 2008 +0100 (2008-07-01) |
parents | c33a40b4c22b |
children | 763c32fdbd13 |
files | tools/examples/xend-config.sxp tools/python/xen/xend/XendOptions.py tools/python/xen/xend/image.py |
line diff
1.1 --- a/tools/examples/xend-config.sxp Mon Jun 30 14:19:09 2008 +0100 1.2 +++ b/tools/examples/xend-config.sxp Tue Jul 01 10:58:43 2008 +0100 1.3 @@ -242,3 +242,6 @@ 1.4 1.5 # Script to run when the label of a resource has changed. 1.6 #(resource-label-change-script '') 1.7 + 1.8 +# Rotation count of qemu-dm log file. 1.9 +#(qemu-dm-logrotate-count 10)
2.1 --- a/tools/python/xen/xend/XendOptions.py Mon Jun 30 14:19:09 2008 +0100 2.2 +++ b/tools/python/xen/xend/XendOptions.py Tue Jul 01 10:58:43 2008 +0100 2.3 @@ -132,6 +132,9 @@ class XendOptions: 2.4 """Default script to configure a backend network interface""" 2.5 vif_script = osdep.vif_script 2.6 2.7 + """Default rotation count of qemu-dm log file.""" 2.8 + qemu_dm_logrotate_count = 10 2.9 + 2.10 def __init__(self): 2.11 self.configure() 2.12 2.13 @@ -351,6 +354,10 @@ class XendOptions: 2.14 def get_vnc_x509_verify(self): 2.15 return self.get_config_string('vnc-x509-verify', self.xend_vnc_x509_verify) 2.16 2.17 + def get_qemu_dm_logrotate_count(self): 2.18 + return self.get_config_int("qemu-dm-logrotate-count", 2.19 + self.qemu_dm_logrotate_count) 2.20 + 2.21 2.22 class XendOptionsFile(XendOptions): 2.23
3.1 --- a/tools/python/xen/xend/image.py Mon Jun 30 14:19:09 2008 +0100 3.2 +++ b/tools/python/xen/xend/image.py Tue Jul 01 10:58:43 2008 +0100 3.3 @@ -378,10 +378,18 @@ class ImageHandler: 3.4 # keep track of pid and spawned options to kill it later 3.5 3.6 self.logfile = "/var/log/xen/qemu-dm-%s.log" % str(self.vm.info['name_label']) 3.7 - if os.path.exists(self.logfile): 3.8 - if os.path.exists(self.logfile + ".1"): 3.9 - os.unlink(self.logfile + ".1") 3.10 - os.rename(self.logfile, self.logfile + ".1") 3.11 + 3.12 + # rotate log 3.13 + logrotate_count = XendOptions.instance().get_qemu_dm_logrotate_count() 3.14 + if logrotate_count > 0: 3.15 + if os.path.exists("%s.%d" % (self.logfile, logrotate_count)): 3.16 + os.unlink("%s.%d" % (self.logfile, logrotate_count)) 3.17 + for n in range(logrotate_count - 1, 0, -1): 3.18 + if os.path.exists("%s.%d" % (self.logfile, n)): 3.19 + os.rename("%s.%d" % (self.logfile, n), 3.20 + "%s.%d" % (self.logfile, (n + 1))) 3.21 + if os.path.exists(self.logfile): 3.22 + os.rename(self.logfile, self.logfile + ".1") 3.23 3.24 null = os.open("/dev/null", os.O_RDONLY) 3.25 logfd = os.open(self.logfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC|os.O_APPEND)