xend: improve the rotation of qemu-dm logfiles.

Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
This commit is contained in:
Keir Fraser committed 2008-07-01 10:58:43 +01:00
1 parent 1be51142f1
commit da67ff89f7
3 files changed
+22 -4

No files matched your search

+7
View File
@@ -132,6 +132,9 @@ class XendOptions:
"""Default script to configure a backend network interface"""
vif_script = osdep.vif_script
"""Default rotation count of qemu-dm log file."""
qemu_dm_logrotate_count = 10
def __init__(self):
self.configure()
@@ -351,6 +354,10 @@ class XendOptions:
def get_vnc_x509_verify(self):
return self.get_config_string('vnc-x509-verify', self.xend_vnc_x509_verify)
def get_qemu_dm_logrotate_count(self):
return self.get_config_int("qemu-dm-logrotate-count",
self.qemu_dm_logrotate_count)
class XendOptionsFile(XendOptions):
+12 -4
View File
@@ -378,10 +378,18 @@ class ImageHandler:
# keep track of pid and spawned options to kill it later
self.logfile = "/var/log/xen/qemu-dm-%s.log" % str(self.vm.info['name_label'])
if os.path.exists(self.logfile):
if os.path.exists(self.logfile + ".1"):
os.unlink(self.logfile + ".1")
os.rename(self.logfile, self.logfile + ".1")
# rotate log
logrotate_count = XendOptions.instance().get_qemu_dm_logrotate_count()
if logrotate_count > 0:
if os.path.exists("%s.%d" % (self.logfile, logrotate_count)):
os.unlink("%s.%d" % (self.logfile, logrotate_count))
for n in range(logrotate_count - 1, 0, -1):
if os.path.exists("%s.%d" % (self.logfile, n)):
os.rename("%s.%d" % (self.logfile, n),
"%s.%d" % (self.logfile, (n + 1)))
if os.path.exists(self.logfile):
os.rename(self.logfile, self.logfile + ".1")
null = os.open("/dev/null", os.O_RDONLY)
logfd = os.open(self.logfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC|os.O_APPEND)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.