5
5
# twistd -noy sftp.tac
6
6
# or similar. Refer to the twistd(1) man page for details.
10
11
from twisted.application import service
11
12
from twisted.conch.interfaces import ISession
12
13
from twisted.conch.ssh import filetransfer
13
14
from twisted.cred.portal import IRealm, Portal
15
from twisted.internet import task
16
from twisted.internet.error import AlreadyCancelled
14
17
from twisted.protocols.policies import TimeoutFactory
15
18
from twisted.python import components
16
19
from twisted.web.xmlrpc import Proxy
21
from zope.component import getUtility
22
from zope.component.interfaces import ComponentLookupError
18
23
from zope.interface import implements
20
25
from canonical.config import config
21
26
from canonical.launchpad.daemons import readyservice
27
from canonical.launchpad.interfaces.gpghandler import IGPGHandler
22
28
from canonical.launchpad.scripts import execute_zcml_for_scripts
24
30
from lp.poppy import get_poppy_root
69
75
return SFTPServer(avatar, get_poppy_root())
79
"""Manages the twisted job to touch the files in the gpgconfig directory."""
81
self._gpghandler_job = None
82
# stop the GPGHandler job on normal termination.
83
atexit.register(self._stopGPGHandlerJob)
84
# start the GPGHandler job
85
self._scheduleGPGHandlerJob()
87
def _scheduleGPGHandlerJob(self, touch_interval=12 * 3600):
88
# Create a job to touch the GPGHandler home directory every so often
89
# so that it does not get cleaned up by any reaper scripts which look
90
# at time last modified.
92
self._stopGPGHandlerJob()
94
self._gpghandler_job = task.LoopingCall(
95
getUtility(IGPGHandler).touchConfigurationDirectory)
96
return self._gpghandler_job.start(touch_interval)
97
except ComponentLookupError:
98
# No GPGHandler so no need to start the job.
101
def _stopGPGHandlerJob(self):
103
if self._gpghandler_job and self._gpghandler_job.running:
104
self._gpghandler_job.stop()
105
except AlreadyCancelled:
106
# So we're already cancelled, meh.
72
110
# Connect Python logging to Twisted's logging.
73
111
from lp.services.twistedsupport.loggingsupport import set_up_tacfile_logging
74
112
set_up_tacfile_logging("poppy-sftp", logging.INFO)
109
147
# We need Zope for looking up the GPG utilities.
110
148
execute_zcml_for_scripts()
150
# Set up the GPGHandler job
151
gpgHandlerJob = GPGHandlerJob()
112
153
# Service that announces when the daemon is ready
113
154
readyservice.ReadyService().setServiceParent(application)