Merge lp:~cjwatson/launchpad-buildd/log-rotation into lp:launchpad-buildd

Proposed by Colin Watson
Status: Merged
Merged at revision: 143
Proposed branch: lp:~cjwatson/launchpad-buildd/log-rotation
Merge into: lp:launchpad-buildd
Diff against target: 212 lines (+109/-14)
7 files modified
buildd-slave.tac (+25/-12)
debian/changelog (+6/-0)
debian/control (+1/-1)
debian/launchpad-buildd.init (+15/-1)
debian/launchpad-buildd.logrotate (+13/-0)
debian/rules (+1/-0)
lpbuildd/log.py (+48/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad-buildd/log-rotation
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+258780@code.launchpad.net

Commit message

Apply more reasonable log handling, as well as logrotate.

Description of the change

Apply more reasonable log handling, as well as logrotate. This replaces Twisted's horrible default of rotating the file once per million bytes.

I borrowed the RotatableFileLogObserver class from Launchpad, and amended it to use SIGHUP as its reopening signal.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'buildd-slave.tac'
2--- buildd-slave.tac 2014-08-06 07:10:48 +0000
3+++ buildd-slave.tac 2015-05-11 14:38:58 +0000
4@@ -5,19 +5,30 @@
5 # XXX: dsilvers: 2005/01/21: Currently everything logged in the slave gets
6 # passed through to the twistd log too. this could get dangerous/big
7
8-from twisted.application import service, strports
9-from lpbuildd.slave import XMLRPCBuildDSlave
10+from ConfigParser import SafeConfigParser
11+import os
12+
13+from twisted.application import (
14+ service,
15+ strports,
16+ )
17+from twisted.scripts.twistd import ServerOptions
18+from twisted.web import (
19+ resource,
20+ server,
21+ static,
22+ )
23+
24 from lpbuildd.binarypackage import BinaryPackageBuildManager
25 from lpbuildd.livefs import LiveFilesystemBuildManager
26-from lpbuildd.sourcepackagerecipe import (
27- SourcePackageRecipeBuildManager)
28-from lpbuildd.translationtemplates import (
29- TranslationTemplatesBuildManager)
30-
31-from twisted.web import server, resource, static
32-from ConfigParser import SafeConfigParser
33-
34-import os
35+from lpbuildd.log import RotatableFileLogObserver
36+from lpbuildd.slave import XMLRPCBuildDSlave
37+from lpbuildd.sourcepackagerecipe import SourcePackageRecipeBuildManager
38+from lpbuildd.translationtemplates import TranslationTemplatesBuildManager
39+
40+
41+options = ServerOptions()
42+options.parseOptions()
43
44 conffile = os.environ.get('BUILDD_SLAVE_CONFIG', 'buildd-slave-example.conf')
45
46@@ -32,6 +43,8 @@
47 slave.registerBuilder(LiveFilesystemBuildManager, "livefs")
48
49 application = service.Application('BuildDSlave')
50+application.addComponent(
51+ RotatableFileLogObserver(options.get('logfile')), ignoreClass=1)
52 builddslaveService = service.IServiceCollection(application)
53
54 root = resource.Resource()
55@@ -39,7 +52,7 @@
56 root.putChild('filecache', static.File(conf.get('slave', 'filecache')))
57 slavesite = server.Site(root)
58
59-strports.service(slave.slave._config.get("slave","bindport"),
60+strports.service(slave.slave._config.get("slave", "bindport"),
61 slavesite).setServiceParent(builddslaveService)
62
63 # You can interact with a running slave like this:
64
65=== modified file 'debian/changelog'
66--- debian/changelog 2015-04-17 20:49:23 +0000
67+++ debian/changelog 2015-05-11 14:38:58 +0000
68@@ -1,7 +1,13 @@
69 launchpad-buildd (127) UNRELEASED; urgency=low
70
71+ [ William Grant ]
72 * Refactor lpbuildd.binarypackage tests to be readable.
73
74+ [ Colin Watson ]
75+ * Apply more reasonable log handling, as well as logrotate.
76+ RotatableFileLogObserver class borrowed from Launchpad, amended to use
77+ SIGHUP as its reopening signal.
78+
79 -- William Grant <wgrant@ubuntu.com> Sat, 18 Apr 2015 06:41:52 +1000
80
81 launchpad-buildd (126) trusty; urgency=medium
82
83=== modified file 'debian/control'
84--- debian/control 2014-06-25 01:50:28 +0000
85+++ debian/control 2015-05-11 14:38:58 +0000
86@@ -22,7 +22,7 @@
87 Package: python-lpbuildd
88 Section: python
89 Architecture: all
90-Depends: python, python-twisted-core, python-twisted-web, python-apt, ${misc:Depends}
91+Depends: python, python-twisted-core, python-twisted-web, python-zope.interface, python-apt, ${misc:Depends}
92 Breaks: launchpad-buildd (<< 88)
93 Replaces: launchpad-buildd (<< 88)
94 Description: Python libraries for a Launchpad buildd slave
95
96=== modified file 'debian/launchpad-buildd.init'
97--- debian/launchpad-buildd.init 2011-11-11 13:43:50 +0000
98+++ debian/launchpad-buildd.init 2015-05-11 14:38:58 +0000
99@@ -92,6 +92,15 @@
100 test -r $PIDFILE && kill -TERM $(cat $PIDFILE) || true
101 }
102
103+#
104+# Function that reloads a buildd slave
105+#
106+d_reload() {
107+ CONF=$1
108+ PIDFILE="$PIDROOT"/"$CONF".pid
109+ test -r $PIDFILE && kill -HUP $(cat $PIDFILE) || true
110+}
111+
112 CONFS=$(cd $CONFROOT; ls|grep -v "^-"|grep -v "~$")
113
114 case "$1" in
115@@ -128,8 +137,13 @@
116 sleep 1
117 $0 start
118 ;;
119+ reload)
120+ for conf in $CONFS; do
121+ d_reload $conf
122+ done
123+ ;;
124 *)
125- echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
126+ echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|reload}" >&2
127 exit 1
128 ;;
129 esac
130
131=== added file 'debian/launchpad-buildd.logrotate'
132--- debian/launchpad-buildd.logrotate 1970-01-01 00:00:00 +0000
133+++ debian/launchpad-buildd.logrotate 2015-05-11 14:38:58 +0000
134@@ -0,0 +1,13 @@
135+/var/log/launchpad-buildd/*.log {
136+ rotate 14
137+ daily
138+ dateext
139+ delaycompress
140+ compress
141+ notifempty
142+ missingok
143+ create 0644 buildd buildd
144+ postrotate
145+ service launchpad-buildd reload
146+ endscript
147+}
148
149=== modified file 'debian/rules'
150--- debian/rules 2014-08-04 23:40:28 +0000
151+++ debian/rules 2015-05-11 14:38:58 +0000
152@@ -45,6 +45,7 @@
153 dh_installchangelogs
154 dh_installinit
155 dh_installcron
156+ dh_installlogrotate
157 dh_strip
158 dh_compress
159 dh_fixperms
160
161=== added file 'lpbuildd/log.py'
162--- lpbuildd/log.py 1970-01-01 00:00:00 +0000
163+++ lpbuildd/log.py 2015-05-11 14:38:58 +0000
164@@ -0,0 +1,48 @@
165+# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
166+# GNU Affero General Public License version 3 (see the file LICENSE).
167+
168+from __future__ import (
169+ absolute_import,
170+ print_function,
171+ unicode_literals,
172+ )
173+
174+import signal
175+import sys
176+
177+from twisted.internet import reactor
178+from twisted.python import (
179+ log,
180+ logfile,
181+ )
182+from zope.interface import implements
183+
184+
185+class RotatableFileLogObserver:
186+ """A log observer that uses a log file and reopens it on SIGHUP."""
187+
188+ implements(log.ILogObserver)
189+
190+ def __init__(self, logfilepath):
191+ """Set up the logfile and possible signal handler.
192+
193+ Installs the signal handler for SIGHUP to make the process re-open
194+ the log file.
195+
196+ :param logfilepath: The path to the logfile. If None, stdout is used
197+ for logging and no signal handler will be installed.
198+ """
199+ if logfilepath is None:
200+ logFile = sys.stdout
201+ else:
202+ logFile = logfile.LogFile.fromFullPath(
203+ logfilepath, rotateLength=None)
204+ # Override if signal is set to None or SIG_DFL (0)
205+ if not signal.getsignal(signal.SIGHUP):
206+ def signalHandler(signal, frame):
207+ reactor.callFromThread(logFile.reopen)
208+ signal.signal(signal.SIGHUP, signalHandler)
209+ self.observer = log.FileLogObserver(logFile)
210+
211+ def __call__(self, eventDict):
212+ self.observer.emit(eventDict)

Subscribers

People subscribed via source and target branches

to all changes: