Merge pull request #678 from tahoe-lafs/2239.remove-tahoesvc-and-pkgresutil

Remove tahoesvc and pkgresutil

Fixes: ticket:2239
This commit is contained in:
Jean-Paul Calderone 2020-02-11 13:29:46 -05:00 committed by GitHub
commit f032cd50d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 224 deletions

View File

@ -0,0 +1 @@
Untested and unmaintained code for running Tahoe-LAFS as a Windows service has been removed.

View File

@ -19,7 +19,6 @@ BLACKLIST = {
"allmydata.watchdog.inotify",
"allmydata.windows.inotify",
"allmydata.windows.registry",
"allmydata.windows.tahoesvc",
}

View File

@ -1,46 +0,0 @@
def install():
"""
This installs a hook into setuptools' pkg_resources infrastructure, so that resource
files can be found in files relative to the runnin executable, in addition to the
usual egg and source lookup mechanisms. This overrides the ZipProvider, since that
is the lookup mechanism triggered within pkg_resources when running code out of a
py2exe or py2app build's library.zip.
"""
import os, sys
import pkg_resources, zipimport
platform_libdirs = {
'darwin': '../Resources/pkg_resources',
}
exedir = os.path.dirname(sys.executable)
libdir = platform_libdirs.get(sys.platform, 'pkg_resources')
class Provider(pkg_resources.ZipProvider):
def __init__(self, module):
self._module_name = module.__name__
pkg_resources.ZipProvider.__init__(self, module)
def get_resource_filename(self, manager, resource_name):
#print 'get_resource_filename(%s, %s)' % (manager, resource_name)
path = [exedir, libdir] + self._module_name.split('.') + [resource_name]
localfile = os.path.join(*path)
#print ' checking(%s)' % (localfile,)
if os.path.exists(localfile):
#print 'found locally'
return localfile
else:
try:
ret = pkg_resources.ZipProvider.get_resource_filename(self, manager, resource_name)
#print 'returning %s' % (ret,)
return ret
except NotImplementedError:
#print 'get_resource_filename(%s,%s): not found' % (self._module_name, resource_name)
#import traceback
#traceback.print_exc()
return ''
pkg_resources.register_loader_type(zipimport.zipimporter, Provider)

View File

@ -1,177 +0,0 @@
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import win32serviceutil
import win32service
import win32event
import win32evtlogutil
import os
import thread
import time
import traceback
# this logging should go away once service startup is considered debugged.
logfilehandle = file('c:\\tahoe_service.log', 'ab+')
def logmsg(msg):
logfilehandle.write("%s: %s\r\n" % (time.strftime('%Y%m%d_%H%M%S'), msg))
logfilehandle.flush()
logmsg('service loaded')
#
# Now with some bootstrap util functions in place, let's try and init things:
try:
from allmydata.util import pkgresutil # override pkg_resources zip provider for py2exe deployment
pkgresutil.install() # this is done before nevow is imported
logmsg('loading base dir')
from allmydata.windows import registry
basedir = registry.get_base_dir_path()
logmsg("got base dir (%s)" % (basedir,))
if not basedir:
regpth = "%s : %s " % (registry._AMD_KEY, registry._BDIR_KEY)
raise RuntimeError('"%s" not set in registry' % (regpth,))
os.chdir(basedir)
logmsg("chdir(%s)" % (basedir,))
except:
logmsg("exception")
traceback.print_exc(None, logfilehandle)
logfilehandle.flush()
logfilehandle.close()
raise
class Tahoe(win32serviceutil.ServiceFramework):
_svc_name_ = "Tahoe"
_svc_display_name_ = "Tahoe-LAFS Node"
def __init__(self, args):
logmsg("init")
try:
# The exe-file has messages for the Event Log Viewer.
# Register the exe-file as event source.
#
# Probably it would be better if this is done at installation time,
# so that it also could be removed if the service is uninstalled.
# Unfortunately it cannot be done in the 'if __name__ == "__main__"'
# block below, because the 'frozen' exe-file does not run this code.
#
logmsg("service start")
win32evtlogutil.AddSourceToRegistry(self._svc_display_name_,
sys.executable,
"Application")
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
except:
try:
logmsg("exception")
traceback.print_exc(None, logfilehandle)
logfilehandle.flush()
logfilehandle.close()
except:
os.abort()
def SvcStop(self):
logmsg("service stop")
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
try:
logmsg("service run")
import servicemanager
# Write a 'started' event to the event log...
win32evtlogutil.ReportEvent(self._svc_display_name_,
servicemanager.PYS_SERVICE_STARTED,
0, # category
servicemanager.EVENTLOG_INFORMATION_TYPE,
(self._svc_name_, ''))
reactor_type = registry.get_registry_value('reactor')
if reactor_type == 'iocp':
from twisted.internet import iocpreactor
iocpreactor.install()
else:
from twisted.internet import selectreactor
selectreactor.install()
from twisted.internet import reactor
if os.path.exists('DISABLE_STARTUP'):
logmsg("DISABLE_STARTUP exists: exiting")
else:
logmsg("runing reactorthread")
# launch main thread...
thread.start_new_thread(self.launch_node, ())
# ...and block until service stop request
win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
logmsg("wake up")
reactor.callFromThread(reactor.stop)
time.sleep(2) # give the node/reactor a chance to cleanup
# and write a 'stopped' event to the event log.
win32evtlogutil.ReportEvent(self._svc_display_name_,
servicemanager.PYS_SERVICE_STOPPED,
0, # category
servicemanager.EVENTLOG_INFORMATION_TYPE,
(self._svc_name_, ''))
except:
try:
logmsg("exception")
traceback.print_exc(None, logfilehandle)
logfilehandle.flush()
logfilehandle.close()
except:
os.abort()
def launch_node(self):
try:
logmsg("main thread startup")
# import dependencies so that py2exe finds them
# nevow requires all these for its voodoo module import time adaptor registrations
from nevow import accessors, appserver, static, rend, url, util, query, i18n, flat
from nevow import guard, stan, testutil, context
from nevow.flat import flatmdom, flatstan, twist
from formless import webform, processors, annotate, iformless
from decimal import Decimal
import allmydata.web
# junk to appease pyflakes's outrage at py2exe's needs
[
accessors, appserver, static, rend, url, util, query, i18n, flat, guard, stan, testutil,
context, flatmdom, flatstan, twist, webform, processors, annotate, iformless, Decimal,
allmydata,
]
from twisted.internet import reactor
from twisted.python import log, logfile
from allmydata import client
# set up twisted logging. this will become part of the node rsn.
logdir = os.path.join(basedir, 'logs')
if not os.path.exists(logdir):
os.makedirs(logdir)
lf = logfile.LogFile('tahoesvc.log', logdir)
log.startLogging(lf)
# run the node itself
c = client.Client(basedir)
reactor.callLater(0, c.startService) # after reactor startup
reactor.run(installSignalHandlers=False)
logmsg("main thread shutdown")
except:
logmsg("exception")
traceback.print_exc(None, logfilehandle)
logfilehandle.flush()
os.abort()
if __name__ == '__main__':
logmsg("service main")
win32serviceutil.HandleCommandLine(Tahoe)