Merge ~hloeung/container-log-archive-charm:fixes into container-log-archive-charm:master

Proposed by Haw Loeung
Status: Merged
Approved by: Barry Price
Approved revision: 4553c33c6ec0f09035309769119249ee3d20bb03
Merged at revision: 2d8783355324f5b87e6e1aa0634b216ea38cd0f2
Proposed branch: ~hloeung/container-log-archive-charm:fixes
Merge into: container-log-archive-charm:master
Diff against target: 69 lines (+10/-11)
2 files modified
hooks/hooks.py (+9/-7)
templates/logrotate.tmpl (+1/-4)
Reviewer Review Type Date Requested Status
Barry Price Approve
Canonical IS Reviewers Pending
Review via email: mp+425014@code.launchpad.net

Commit message

Set correct ownership and group for log files - LP:1949803

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Barry Price (barryprice) wrote :

LGTM +1

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 2d8783355324f5b87e6e1aa0634b216ea38cd0f2

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/hooks/hooks.py b/hooks/hooks.py
2index f9ac138..e71de24 100755
3--- a/hooks/hooks.py
4+++ b/hooks/hooks.py
5@@ -3,11 +3,11 @@
6 # Copyright 2014 Canonical Ltd. All rights reserved
7 # Author: Chris Stratford <chris.stratford@canonical.com>
8
9+import grp
10 import os
11 import os.path
12 import pwd
13 import random
14-import shutil
15 import stat
16 import sys
17 import socket
18@@ -259,7 +259,6 @@ def deconfigure_nrpe():
19 def configure_logrotate():
20 log_path = "/var/log/container-log-archive.log"
21 logrotate_etcdir = "/etc/logrotate.d"
22- logrotate_file = "files/container-log-archive.logrotate"
23 logrotate_path = os.path.join(logrotate_etcdir, "container-log-archive")
24 # Initialise the log file with the correct permissions
25 with open(log_path, "w"):
26@@ -268,14 +267,17 @@ def configure_logrotate():
27 try:
28 r = pwd.getpwnam(conf.archive_username())
29 gid = r.pw_gid
30+ group = grp.getgrgid(gid).gr_name
31 except KeyError:
32 gid = 0
33+ group = 'root'
34 os.chown(log_path, 0, gid)
35- try:
36- shutil.copyfile(logrotate_file, logrotate_path)
37- except OSError as e:
38- log("CHARM: Failed to copy logrotate file {} to {}".format(logrotate_file, logrotate_path))
39- raise(e)
40+
41+ tmpl_data = {}
42+ tmpl_data["username"] = conf.archive_username()
43+ tmpl_data["group"] = group
44+ file_from_template("logrotate.tmpl", logrotate_path, tmpl_data)
45+ log("CHARM: Wrote logrotate file {}".format(logrotate_path))
46
47
48 def remove_legacy_files():
49diff --git a/files/container-log-archive.logrotate b/templates/logrotate.tmpl
50similarity index 76%
51rename from files/container-log-archive.logrotate
52rename to templates/logrotate.tmpl
53index ae743eb..23f0f09 100644
54--- a/files/container-log-archive.logrotate
55+++ b/templates/logrotate.tmpl
56@@ -1,6 +1,3 @@
57-#-------------------------------------------------#
58-# This file is Juju managed - do not edit by hand #
59-#-------------------------------------------------#
60 /var/log/container-log-archive.log {
61 rotate 7
62 daily
63@@ -8,5 +5,5 @@
64 compress
65 notifempty
66 missingok
67- create 0664 root log-archive
68+ create 0664 {{username}} {{group}}
69 }

Subscribers

People subscribed via source and target branches