~launchpad-pqm/launchpad/devel

8687.15.8 by Karl Fogel
Add the copyright header block to more files.
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
1628 by Canonical.com Patch Queue Manager
Configuration, Librian and Librarian test harness work
3
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
4
# Twisted Application Configuration file.
2237 by Canonical.com Patch Queue Manager
[trivial] Libraraian upstream tweaks, which demonstrate the the feature is broken (?)
5
# Use with "twistd2.4 -y <file.tac>", e.g. "twistd -noy server.tac"
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
6
11737.4.6 by Robert Collins
Make the librarian use dynamically allocated ports and root dir (except when in production / persistent test services).
7
import os
10739.3.1 by Guilherme Salgado
Make the librarian dump its memory (using meliae) upon a 'kill -44'
8
import signal
9
10
from meliae import scanner
11
6998.3.2 by Guilherme Salgado
fix the bug.
12
from twisted.application import service, strports
11784.2.1 by Gary Poster
add diagnostics for why the librarian rejects requests, for diagnosing bug 662912.
13
from twisted.internet import reactor
14
from twisted.python import log
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
15
from twisted.web import server
16
4450.7.1 by James Henstridge
move librarian over to use the webapp database adapter
17
from canonical.config import config, dbconfig
11765.1.1 by Robert Collins
Split out the launchpad-buildd needed component from tachandler.py.
18
from canonical.launchpad.daemons import readyservice
4450.7.1 by James Henstridge
move librarian over to use the webapp database adapter
19
from canonical.launchpad.scripts import execute_zcml_for_scripts
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
20
10739.3.1 by Guilherme Salgado
Make the librarian dump its memory (using meliae) upon a 'kill -44'
21
from canonical.librarian.interfaces import DUMP_FILE, SIGDUMPMEM
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
22
from canonical.librarian.libraryprotocol import FileUploadFactory
23
from canonical.librarian import storage, db
24
from canonical.librarian import web as fatweb
11221.1.1 by Robert Collins
Start logging oops from the librarian. Fixes lp:86185
25
from lp.services.twistedsupport.loggingsupport import set_up_oops_reporting
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
26
27
# Connect to database
13993.1.2 by William Grant
librarian no longer uses setConfigSection.
28
dbconfig.override(
29
    dbuser=config.librarian.dbuser,
30
    isolation_level=config.librarian.isolation_level)
4450.7.1 by James Henstridge
move librarian over to use the webapp database adapter
31
execute_zcml_for_scripts()
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
32
11737.4.6 by Robert Collins
Make the librarian use dynamically allocated ports and root dir (except when in production / persistent test services).
33
if os.environ.get('LP_TEST_INSTANCE'):
34
    # Running in ephemeral mode: get the root dir from the environment and
35
    # dynamically allocate ports.
36
    path = os.environ['LP_LIBRARIAN_ROOT']
37
else:
38
    path = config.librarian_server.root
5863.9.2 by Curtis Hovey
Updated code to use the libraran_server section.
39
if config.librarian_server.upstream_host:
40
    upstreamHost = config.librarian_server.upstream_host
41
    upstreamPort = config.librarian_server.upstream_port
11784.2.2 by Gary Poster
switch callWhenRunning to addSystemEventTrigger because it is clearer about intent.
42
    reactor.addSystemEventTrigger(
43
        'before', 'startup', log.msg,
11784.2.1 by Gary Poster
add diagnostics for why the librarian rejects requests, for diagnosing bug 662912.
44
        'Using upstream librarian http://%s:%d' %
45
        (upstreamHost, upstreamPort))
2109 by Canonical.com Patch Queue Manager
[trivial] Add upstream librarian support for the staging environment
46
else:
47
    upstreamHost = upstreamPort = None
11784.2.2 by Gary Poster
switch callWhenRunning to addSystemEventTrigger because it is clearer about intent.
48
    reactor.addSystemEventTrigger(
49
        'before', 'startup', log.msg, 'Not using upstream librarian')
6998.3.2 by Guilherme Salgado
fix the bug.
50
51
application = service.Application('Librarian')
52
librarianService = service.IServiceCollection(application)
53
54
# Service that announces when the daemon is ready
11765.1.1 by Robert Collins
Split out the launchpad-buildd needed component from tachandler.py.
55
readyservice.ReadyService().setServiceParent(librarianService)
6998.3.2 by Guilherme Salgado
fix the bug.
56
6998.3.3 by Guilherme Salgado
A couple changes after Francis' review
57
def setUpListener(uploadPort, webPort, restricted):
58
    """Set up a librarian listener on the given ports.
59
60
    :param restricted: Should this be a restricted listener?  A restricted
61
        listener will serve only files with the 'restricted' file set and all
62
        files uploaded through the restricted listener will have that flag
63
        set.
64
    """
65
    librarian_storage = storage.LibrarianStorage(
66
        path, db.Library(restricted=restricted))
67
    upload_factory = FileUploadFactory(librarian_storage)
12581.2.1 by Gavin Panella
Do as the warnings suggest.
68
    strports.service("tcp:%d" % uploadPort, upload_factory).setServiceParent(
6998.3.3 by Guilherme Salgado
A couple changes after Francis' review
69
        librarianService)
70
    root = fatweb.LibraryFileResource(
71
        librarian_storage, upstreamHost, upstreamPort)
72
    root.putChild('search', fatweb.DigestSearchResource(librarian_storage))
73
    root.putChild('robots.txt', fatweb.robotsTxt)
74
    site = server.Site(root)
75
    site.displayTracebacks = False
12581.2.1 by Gavin Panella
Do as the warnings suggest.
76
    strports.service("tcp:%d" % webPort, site).setServiceParent(
77
        librarianService)
6998.3.3 by Guilherme Salgado
A couple changes after Francis' review
78
11737.4.6 by Robert Collins
Make the librarian use dynamically allocated ports and root dir (except when in production / persistent test services).
79
if os.environ.get('LP_TEST_INSTANCE'):
80
    # Running in ephemeral mode: allocate ports on demand.
81
    setUpListener(0, 0, restricted=False)
82
    setUpListener(0, 0, restricted=True)
83
else:
84
    # Set up the public librarian.
85
    uploadPort = config.librarian.upload_port
86
    webPort = config.librarian.download_port
87
    setUpListener(uploadPort, webPort, restricted=False)
88
    # Set up the restricted librarian.
89
    webPort = config.librarian.restricted_download_port
90
    uploadPort = config.librarian.restricted_upload_port
91
    setUpListener(uploadPort, webPort, restricted=True)
10739.3.1 by Guilherme Salgado
Make the librarian dump its memory (using meliae) upon a 'kill -44'
92
11221.1.1 by Robert Collins
Start logging oops from the librarian. Fixes lp:86185
93
# Log OOPS reports
94
set_up_oops_reporting('librarian', 'librarian')
95
10739.3.1 by Guilherme Salgado
Make the librarian dump its memory (using meliae) upon a 'kill -44'
96
# Setup a signal handler to dump the process' memory upon 'kill -44'.
97
def sigdumpmem_handler(signum, frame):
98
    scanner.dump_all_objects(DUMP_FILE)
99
100
signal.signal(SIGDUMPMEM, sigdumpmem_handler)