~launchpad-pqm/launchpad/devel

12221.16.16 by Andrew Bennetts
Reorder some imports and update copyright years as requested by Aaron's review.
1
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
8687.15.8 by Karl Fogel
Add the copyright header block to more files.
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
0.1.8 by Andrew Bennetts
Copyright notices, explain how to use .tac file
4
# This is a Twisted application config file.  To run, use:
5
#     twistd -noy sftp.tac
6
# or similar.  Refer to the twistd(1) man page for details.
7
3858.1.12 by jml at canonical
Make the SFTP tac file use the service defined in c.l.daemons.sftp
8
from twisted.application import service
12221.16.4 by Andrew Bennetts
Move new stuff to new lp.services.twistedsupport.gracefulshutdown module, add OrderedMultiService.
9
from twisted.protocols.policies import TimeoutFactory
3858.1.12 by jml at canonical
Make the SFTP tac file use the service defined in c.l.daemons.sftp
10
10693.2.11 by Jonathan Lange
Parametrize a bunch of other things
11
from canonical.config import config
11765.1.1 by Robert Collins
Split out the launchpad-buildd needed component from tachandler.py.
12
from canonical.launchpad.daemons import readyservice
10693.2.11 by Jonathan Lange
Parametrize a bunch of other things
13
10693.3.27 by Jonathan Lange
Move the codehosting-specific stuff out of service and into daemon
14
from lp.codehosting.sshserver.daemon import (
12221.16.16 by Andrew Bennetts
Reorder some imports and update copyright years as requested by Aaron's review.
15
    ACCESS_LOG_NAME,
16
    get_key_path,
17
    LOG_NAME,
18
    make_portal,
19
    OOPS_CONFIG_SECTION,
20
    PRIVATE_KEY_FILE,
21
    PUBLIC_KEY_FILE,
22
    )
10693.5.6 by Jonathan Lange
Move the service logic
23
from lp.services.sshserver.service import SSHService
12221.16.4 by Andrew Bennetts
Move new stuff to new lp.services.twistedsupport.gracefulshutdown module, add OrderedMultiService.
24
from lp.services.twistedsupport.gracefulshutdown import (
12221.16.16 by Andrew Bennetts
Reorder some imports and update copyright years as requested by Aaron's review.
25
    ConnTrackingFactoryWrapper,
26
    make_web_status_service,
27
    OrderedMultiService,
28
    ShutdownCleanlyService,
29
    )
10693.2.7 by Jonathan Lange
Parametrize the portal in the SSH service
30
31
10693.2.8 by Jonathan Lange
Fix old, old comment
32
# Construct an Application that has the codehosting SSH server.
0.1.3 by Andrew Bennetts
Remove cruft, flesh out the code and a sample tac file a bit more
33
application = service.Application('sftponly')
12221.16.1 by Andrew Bennetts
Initial hackery towards #702024.
34
12221.16.4 by Andrew Bennetts
Move new stuff to new lp.services.twistedsupport.gracefulshutdown module, add OrderedMultiService.
35
ordered_services = OrderedMultiService()
36
ordered_services.setServiceParent(application)
37
12221.16.1 by Andrew Bennetts
Initial hackery towards #702024.
38
tracked_factories = set()
39
12221.16.13 by Andrew Bennetts
Add make_web_status_service function to simplify the tac file.
40
web_svc = make_web_status_service(
41
    config.codehosting.web_status_port, tracked_factories)
42
web_svc.setServiceParent(ordered_services)
43
44
shutdown_cleanly_svc = ShutdownCleanlyService(tracked_factories)
45
shutdown_cleanly_svc.setServiceParent(ordered_services)
46
47
def ssh_factory_decorator(factory):
12221.16.15 by Andrew Bennetts
Docstrings and cosmetic code changes requested by Aaron's review.
48
    """Add idle timeouts and connection tracking to a factory."""
12221.16.1 by Andrew Bennetts
Initial hackery towards #702024.
49
    f = TimeoutFactory(factory, timeoutPeriod=config.codehosting.idle_timeout)
12221.16.10 by Andrew Bennetts
Add some tests for ConnTrackingFactoryWrapper.
50
    f = ConnTrackingFactoryWrapper(f)
12221.16.1 by Andrew Bennetts
Initial hackery towards #702024.
51
    tracked_factories.add(f)
52
    return f
53
10693.2.9 by Jonathan Lange
Push the key path parametrization out to the SSH service
54
svc = SSHService(
55
    portal=make_portal(),
56
    private_key_path=get_key_path(PRIVATE_KEY_FILE),
10693.2.11 by Jonathan Lange
Parametrize a bunch of other things
57
    public_key_path=get_key_path(PUBLIC_KEY_FILE),
10693.4.2 by Jonathan Lange
Fix a bunch of stupid oversights
58
    oops_configuration=OOPS_CONFIG_SECTION,
59
    main_log=LOG_NAME,
60
    access_log=ACCESS_LOG_NAME,
61
    access_log_path=config.codehosting.access_log,
10693.2.19 by Jonathan Lange
Fix invocation
62
    strport=config.codehosting.port,
12221.16.13 by Andrew Bennetts
Add make_web_status_service function to simplify the tac file.
63
    factory_decorator=ssh_factory_decorator,
10693.2.11 by Jonathan Lange
Parametrize a bunch of other things
64
    banner=config.codehosting.banner)
12221.16.1 by Andrew Bennetts
Initial hackery towards #702024.
65
svc.setServiceParent(shutdown_cleanly_svc)
0.1.3 by Andrew Bennetts
Remove cruft, flesh out the code and a sample tac file a bit more
66
2902.2.32 by Andrew Bennetts
Move authserver config into launchpad.conf; remove test-only variants of authserver.tac and sftp.tac; remove a hard-coded path from a test.
67
# Service that announces when the daemon is ready
11765.1.1 by Robert Collins
Split out the launchpad-buildd needed component from tachandler.py.
68
readyservice.ReadyService().setServiceParent(application)