~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
4450.7.1 by James Henstridge
move librarian over to use the webapp database adapter
28
dbconfig.setConfigSection('librarian')
29
execute_zcml_for_scripts()
1102 by Canonical.com Patch Queue Manager
Lucille had some XXXs which should have been NOTEs
30
11737.4.6 by Robert Collins
Make the librarian use dynamically allocated ports and root dir (except when in production / persistent test services).
31
if os.environ.get('LP_TEST_INSTANCE'):
32
    # Running in ephemeral mode: get the root dir from the environment and
33
    # dynamically allocate ports.
34
    path = os.environ['LP_LIBRARIAN_ROOT']
35
else:
36
    path = config.librarian_server.root
5863.9.2 by Curtis Hovey
Updated code to use the libraran_server section.
37
if config.librarian_server.upstream_host:
38
    upstreamHost = config.librarian_server.upstream_host
39
    upstreamPort = config.librarian_server.upstream_port
11784.2.2 by Gary Poster
switch callWhenRunning to addSystemEventTrigger because it is clearer about intent.
40
    reactor.addSystemEventTrigger(
41
        'before', 'startup', log.msg,
11784.2.1 by Gary Poster
add diagnostics for why the librarian rejects requests, for diagnosing bug 662912.
42
        'Using upstream librarian http://%s:%d' %
43
        (upstreamHost, upstreamPort))
2109 by Canonical.com Patch Queue Manager
[trivial] Add upstream librarian support for the staging environment
44
else:
45
    upstreamHost = upstreamPort = None
11784.2.2 by Gary Poster
switch callWhenRunning to addSystemEventTrigger because it is clearer about intent.
46
    reactor.addSystemEventTrigger(
47
        'before', 'startup', log.msg, 'Not using upstream librarian')
6998.3.2 by Guilherme Salgado
fix the bug.
48
49
application = service.Application('Librarian')
50
librarianService = service.IServiceCollection(application)
51
52
# Service that announces when the daemon is ready
11765.1.1 by Robert Collins
Split out the launchpad-buildd needed component from tachandler.py.
53
readyservice.ReadyService().setServiceParent(librarianService)
6998.3.2 by Guilherme Salgado
fix the bug.
54
6998.3.3 by Guilherme Salgado
A couple changes after Francis' review
55
def setUpListener(uploadPort, webPort, restricted):
56
    """Set up a librarian listener on the given ports.
57
58
    :param restricted: Should this be a restricted listener?  A restricted
59
        listener will serve only files with the 'restricted' file set and all
60
        files uploaded through the restricted listener will have that flag
61
        set.
62
    """
63
    librarian_storage = storage.LibrarianStorage(
64
        path, db.Library(restricted=restricted))
65
    upload_factory = FileUploadFactory(librarian_storage)
12581.2.1 by Gavin Panella
Do as the warnings suggest.
66
    strports.service("tcp:%d" % uploadPort, upload_factory).setServiceParent(
6998.3.3 by Guilherme Salgado
A couple changes after Francis' review
67
        librarianService)
68
    root = fatweb.LibraryFileResource(
69
        librarian_storage, upstreamHost, upstreamPort)
70
    root.putChild('search', fatweb.DigestSearchResource(librarian_storage))
71
    root.putChild('robots.txt', fatweb.robotsTxt)
72
    site = server.Site(root)
73
    site.displayTracebacks = False
12581.2.1 by Gavin Panella
Do as the warnings suggest.
74
    strports.service("tcp:%d" % webPort, site).setServiceParent(
75
        librarianService)
6998.3.3 by Guilherme Salgado
A couple changes after Francis' review
76
11737.4.6 by Robert Collins
Make the librarian use dynamically allocated ports and root dir (except when in production / persistent test services).
77
if os.environ.get('LP_TEST_INSTANCE'):
78
    # Running in ephemeral mode: allocate ports on demand.
79
    setUpListener(0, 0, restricted=False)
80
    setUpListener(0, 0, restricted=True)
81
else:
82
    # Set up the public librarian.
83
    uploadPort = config.librarian.upload_port
84
    webPort = config.librarian.download_port
85
    setUpListener(uploadPort, webPort, restricted=False)
86
    # Set up the restricted librarian.
87
    webPort = config.librarian.restricted_download_port
88
    uploadPort = config.librarian.restricted_upload_port
89
    setUpListener(uploadPort, webPort, restricted=True)
10739.3.1 by Guilherme Salgado
Make the librarian dump its memory (using meliae) upon a 'kill -44'
90
11221.1.1 by Robert Collins
Start logging oops from the librarian. Fixes lp:86185
91
# Log OOPS reports
92
set_up_oops_reporting('librarian', 'librarian')
93
10739.3.1 by Guilherme Salgado
Make the librarian dump its memory (using meliae) upon a 'kill -44'
94
# Setup a signal handler to dump the process' memory upon 'kill -44'.
95
def sigdumpmem_handler(signum, frame):
96
    scanner.dump_all_objects(DUMP_FILE)
97
98
signal.signal(SIGDUMPMEM, sigdumpmem_handler)