Merge lp:~cjwatson/launchpad/better-loggerhead-startup into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18686
Proposed branch: lp:~cjwatson/launchpad/better-loggerhead-startup
Merge into: lp:launchpad
Diff against target: 60 lines (+19/-1)
1 file modified
lib/launchpad_loggerhead/wsgi.py (+19/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/better-loggerhead-startup
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+347605@code.launchpad.net

Commit message

Capture loggerhead stdout/stderr to the log, and remove pidfile on exit.

Description of the change

This may fix whatever's wrong with loggerhead on staging at the moment after the switch to gunicorn, but even if it doesn't it should at least make it easier to debug.

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 'lib/launchpad_loggerhead/wsgi.py'
2--- lib/launchpad_loggerhead/wsgi.py 2018-06-04 14:02:57 +0000
3+++ lib/launchpad_loggerhead/wsgi.py 2018-06-07 15:00:16 +0000
4@@ -8,9 +8,12 @@
5 'LoggerheadApplication',
6 ]
7
8+import atexit
9 import logging
10 from optparse import OptionParser
11 import os.path
12+import signal
13+import sys
14 import time
15 import traceback
16
17@@ -29,7 +32,10 @@
18 from launchpad_loggerhead.session import SessionHandler
19 import lp.codehosting
20 from lp.services.config import config
21-from lp.services.pidfile import pidfile_path
22+from lp.services.pidfile import (
23+ pidfile_path,
24+ remove_pidfile,
25+ )
26 from lp.services.scripts import (
27 logger,
28 logger_options,
29@@ -87,6 +93,16 @@
30 oidutil.log = lambda message, level=0: log.debug(message)
31
32
33+def _on_starting_hook(arbiter):
34+ # Normally lp.services.pidfile.make_pidfile does this, but in this case
35+ # we have to do it ourselves since gunicorn creates the pidfile.
36+ atexit.register(remove_pidfile, "codebrowse")
37+ # Register a trivial SIGTERM handler so that the atexit hook is called
38+ # on SIGTERM.
39+ signal.signal(
40+ signal.SIGTERM, lambda signum, frame: sys.exit(-signal.SIGTERM))
41+
42+
43 class LoggerheadApplication(Application):
44
45 def __init__(self, **kwargs):
46@@ -106,12 +122,14 @@
47 "bind": [
48 "%s:%s" % (listen_host, config.codebrowse.port),
49 ],
50+ "capture_output": True,
51 "errorlog": os.path.join(log_folder, "debug.log"),
52 # Trust that firewalls only permit sending requests to
53 # loggerhead via a frontend.
54 "forwarded_allow_ips": "*",
55 "logger_class": "launchpad_loggerhead.wsgi.LoggerheadLogger",
56 "loglevel": "debug",
57+ "on_starting": _on_starting_hook,
58 "pidfile": pidfile_path("codebrowse"),
59 "preload_app": True,
60 # XXX cjwatson 2018-05-15: These are gunicorn defaults plus