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