The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6938

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
This allows non-log files to be kept, such as .monitor and .pid files used for VMs.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
From 7704acc6d66ff832c2ef581ba59af8be6d2dd63e Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Wed, 26 Feb 2020 09:42:54 +0000
Subject: [PATCH] lxd/logging: Updates log rotate to only remove .log files

This allows non-log files to be kept, such as .monitor and .pid files used for 
VMs.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/logging.go | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/lxd/logging.go b/lxd/logging.go
index 86787358dd..21302a9d8e 100644
--- a/lxd/logging.go
+++ b/lxd/logging.go
@@ -4,6 +4,7 @@ import (
        "context"
        "io/ioutil"
        "os"
+       "strings"
        "time"
 
        "github.com/lxc/lxd/lxd/db"
@@ -93,25 +94,19 @@ func expireLogs(ctx context.Context, state *state.State) 
error {
                        continue
                }
 
-               // Check if the container still exists.
+               // Check if the instance still exists.
                if shared.StringInSlice(entry.Name(), names) {
-                       // Remove any log file which wasn't modified in the 
past 48 hours.
-                       logs, err := 
ioutil.ReadDir(shared.LogPath(entry.Name()))
+                       instDirEntries, err := 
ioutil.ReadDir(shared.LogPath(entry.Name()))
                        if err != nil {
                                return err
                        }
 
-                       for _, logfile := range logs {
-                               path := shared.LogPath(entry.Name(), 
logfile.Name())
-
-                               // Always keep the config files.
-                               if logfile.Name() == "lxc.conf" || 
logfile.Name() == "qemu.conf" {
-                                       continue
-                               }
+                       for _, instDirEntry := range instDirEntries {
+                               path := shared.LogPath(entry.Name(), 
instDirEntry.Name())
 
                                // Deal with directories (snapshots).
-                               if logfile.IsDir() {
-                                       newest := newestFile(path, logfile)
+                               if instDirEntry.IsDir() {
+                                       newest := newestFile(path, instDirEntry)
                                        if time.Since(newest).Hours() >= 48 {
                                                err := os.RemoveAll(path)
                                                if err != nil {
@@ -122,8 +117,13 @@ func expireLogs(ctx context.Context, state *state.State) 
error {
                                        continue
                                }
 
-                               // Individual files.
-                               if time.Since(logfile.ModTime()).Hours() >= 48 {
+                               // Only remove old log files (keep other files, 
such as conf, pid, monitor etc).
+                               if !strings.HasSuffix(instDirEntry.Name(), 
".log") {
+                                       continue
+                               }
+
+                               // Remove any log file which wasn't modified in 
the past 48 hours.
+                               if time.Since(instDirEntry.ModTime()).Hours() 
>= 48 {
                                        err := os.Remove(path)
                                        if err != nil {
                                                return err
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to