2007-07-11 02:05:18 +00:00
|
|
|
|
2007-09-20 19:37:50 +00:00
|
|
|
import os, sys, signal, time
|
2012-06-18 17:43:49 +00:00
|
|
|
from allmydata.scripts.common import BasedirOptions
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
from twisted.scripts import twistd
|
|
|
|
from twisted.python import usage
|
2010-10-28 01:48:05 +00:00
|
|
|
from allmydata.util import fileutil
|
2015-01-30 00:04:11 +00:00
|
|
|
from allmydata.util.encodingutil import listdir_unicode, quote_local_unicode_path
|
2007-07-11 02:05:18 +00:00
|
|
|
|
2011-01-22 01:27:00 +00:00
|
|
|
|
2012-06-18 17:43:49 +00:00
|
|
|
class StartOptions(BasedirOptions):
|
2014-10-21 18:15:32 +00:00
|
|
|
subcommand_name = "start"
|
|
|
|
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
def parseArgs(self, basedir=None, *twistd_args):
|
2014-10-21 18:15:32 +00:00
|
|
|
# This can't handle e.g. 'tahoe start --nodaemon', since '--nodaemon'
|
|
|
|
# looks like an option to the tahoe subcommand, not to twistd.
|
|
|
|
# So you can either use 'tahoe start' or 'tahoe start NODEDIR --TWISTD-OPTIONS'.
|
|
|
|
# Note that 'tahoe --node-directory=NODEDIR start --TWISTD-OPTIONS' also
|
|
|
|
# isn't allowed, unfortunately.
|
|
|
|
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
BasedirOptions.parseArgs(self, basedir)
|
|
|
|
self.twistd_args = twistd_args
|
2007-07-11 02:05:18 +00:00
|
|
|
|
2011-01-22 01:27:00 +00:00
|
|
|
def getSynopsis(self):
|
2014-10-21 18:15:32 +00:00
|
|
|
return "Usage: %s [global-opts] %s [options] [NODEDIR [twistd-options]]" % (self.command_name, self.subcommand_name)
|
|
|
|
|
|
|
|
def getUsage(self, width=None):
|
|
|
|
t = BasedirOptions.getUsage(self, width) + "\n"
|
|
|
|
twistd_options = str(MyTwistdConfig()).partition("\n")[2].partition("\n\n")[0]
|
|
|
|
t += twistd_options.replace("Options:", "twistd-options:", 1)
|
|
|
|
t += """
|
2011-01-22 01:27:00 +00:00
|
|
|
|
2014-10-21 18:15:32 +00:00
|
|
|
Note that if any twistd-options are used, NODEDIR must be specified explicitly
|
|
|
|
(not by default or using -C/--basedir or -d/--node-directory), and followed by
|
|
|
|
the twistd-options.
|
|
|
|
"""
|
|
|
|
return t
|
2011-01-22 01:27:00 +00:00
|
|
|
|
2012-06-18 17:43:49 +00:00
|
|
|
class StopOptions(BasedirOptions):
|
2014-10-21 18:15:32 +00:00
|
|
|
def parseArgs(self, basedir=None):
|
|
|
|
BasedirOptions.parseArgs(self, basedir)
|
|
|
|
|
2011-01-22 01:27:00 +00:00
|
|
|
def getSynopsis(self):
|
2012-06-18 17:44:39 +00:00
|
|
|
return "Usage: %s [global-opts] stop [options] [NODEDIR]" % (self.command_name,)
|
2011-01-22 01:27:00 +00:00
|
|
|
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
class RestartOptions(StartOptions):
|
2014-10-21 18:15:32 +00:00
|
|
|
subcommand_name = "restart"
|
2011-01-22 01:27:00 +00:00
|
|
|
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
class RunOptions(StartOptions):
|
2014-10-21 18:15:32 +00:00
|
|
|
subcommand_name = "run"
|
2011-01-22 01:27:00 +00:00
|
|
|
|
|
|
|
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
class MyTwistdConfig(twistd.ServerOptions):
|
2014-10-21 18:04:14 +00:00
|
|
|
subCommands = [("StartTahoeNode", None, usage.Options, "node")]
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
|
2014-10-21 18:04:14 +00:00
|
|
|
class StartTahoeNodePlugin:
|
|
|
|
tapname = "tahoenode"
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
def __init__(self, nodetype, basedir):
|
|
|
|
self.nodetype = nodetype
|
|
|
|
self.basedir = basedir
|
|
|
|
def makeService(self, so):
|
|
|
|
# delay this import as late as possible, to allow twistd's code to
|
|
|
|
# accept --reactor= selection. N.B.: this can't actually work until
|
|
|
|
# this file, and all the __init__.py files above it, also respect the
|
|
|
|
# prohibition on importing anything that transitively imports
|
|
|
|
# twisted.internet.reactor . That will take a lot of work.
|
|
|
|
if self.nodetype == "client":
|
|
|
|
from allmydata.client import Client
|
|
|
|
return Client(self.basedir)
|
|
|
|
if self.nodetype == "introducer":
|
|
|
|
from allmydata.introducer.server import IntroducerNode
|
|
|
|
return IntroducerNode(self.basedir)
|
|
|
|
if self.nodetype == "key-generator":
|
|
|
|
from allmydata.key_generator import KeyGeneratorService
|
|
|
|
return KeyGeneratorService(default_key_size=2048)
|
|
|
|
if self.nodetype == "stats-gatherer":
|
|
|
|
from allmydata.stats import StatsGathererService
|
|
|
|
return StatsGathererService(verbose=True)
|
|
|
|
raise ValueError("unknown nodetype %s" % self.nodetype)
|
|
|
|
|
|
|
|
def identify_node_type(basedir):
|
2010-08-03 08:54:16 +00:00
|
|
|
for fn in listdir_unicode(basedir):
|
|
|
|
if fn.endswith(u".tac"):
|
|
|
|
tac = str(fn)
|
2008-02-18 07:28:17 +00:00
|
|
|
break
|
2007-07-11 02:05:18 +00:00
|
|
|
else:
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
for t in ("client", "introducer", "key-generator", "stats-gatherer"):
|
|
|
|
if t in tac:
|
|
|
|
return t
|
|
|
|
return None
|
|
|
|
|
|
|
|
def start(config, out=sys.stdout, err=sys.stderr):
|
|
|
|
basedir = config['basedir']
|
2015-01-30 00:04:11 +00:00
|
|
|
quoted_basedir = quote_local_unicode_path(basedir)
|
|
|
|
print >>out, "STARTING", quoted_basedir
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
if not os.path.isdir(basedir):
|
2015-01-30 00:04:11 +00:00
|
|
|
print >>err, "%s does not look like a directory at all" % quoted_basedir
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
return 1
|
|
|
|
nodetype = identify_node_type(basedir)
|
|
|
|
if not nodetype:
|
2015-01-30 00:04:11 +00:00
|
|
|
print >>err, "%s is not a recognizable node directory" % quoted_basedir
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
return 1
|
|
|
|
# Now prepare to turn into a twistd process. This os.chdir is the point
|
|
|
|
# of no return.
|
|
|
|
os.chdir(basedir)
|
|
|
|
twistd_args = []
|
|
|
|
if (nodetype in ("client", "introducer")
|
|
|
|
and "--nodaemon" not in config.twistd_args
|
|
|
|
and "--syslog" not in config.twistd_args
|
|
|
|
and "--logfile" not in config.twistd_args):
|
2015-01-30 00:04:11 +00:00
|
|
|
fileutil.make_dirs(os.path.join(basedir, u"logs"))
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
twistd_args.extend(["--logfile", os.path.join("logs", "twistd.log")])
|
|
|
|
twistd_args.extend(config.twistd_args)
|
2014-10-21 18:04:14 +00:00
|
|
|
twistd_args.append("StartTahoeNode") # point at our StartTahoeNodePlugin
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
|
|
|
|
twistd_config = MyTwistdConfig()
|
|
|
|
try:
|
|
|
|
twistd_config.parseOptions(twistd_args)
|
|
|
|
except usage.error, ue:
|
|
|
|
# these arguments were unsuitable for 'twistd'
|
2014-10-21 18:15:32 +00:00
|
|
|
print >>err, config
|
|
|
|
print >>err, "tahoe %s: usage error from twistd: %s\n" % (config.subcommand_name, ue)
|
2007-09-19 08:50:27 +00:00
|
|
|
return 1
|
2014-10-21 18:04:14 +00:00
|
|
|
twistd_config.loadedPlugins = {"StartTahoeNode": StartTahoeNodePlugin(nodetype, basedir)}
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
|
|
|
|
# On Unix-like platforms:
|
|
|
|
# Unless --nodaemon was provided, the twistd.runApp() below spawns off a
|
|
|
|
# child process, and the parent calls os._exit(0), so there's no way for
|
|
|
|
# us to get control afterwards, even with 'except SystemExit'. If
|
|
|
|
# application setup fails (e.g. ImportError), runApp() will raise an
|
|
|
|
# exception.
|
|
|
|
#
|
|
|
|
# So if we wanted to do anything with the running child, we'd have two
|
|
|
|
# options:
|
|
|
|
#
|
|
|
|
# * fork first, and have our child wait for the runApp() child to get
|
|
|
|
# running. (note: just fork(). This is easier than fork+exec, since we
|
|
|
|
# don't have to get PATH and PYTHONPATH set up, since we're not
|
|
|
|
# starting a *different* process, just cloning a new instance of the
|
|
|
|
# current process)
|
|
|
|
# * or have the user run a separate command some time after this one
|
|
|
|
# exits.
|
|
|
|
#
|
|
|
|
# For Tahoe, we don't need to do anything with the child, so we can just
|
|
|
|
# let it exit.
|
|
|
|
#
|
|
|
|
# On Windows:
|
|
|
|
# twistd does not fork; it just runs in the current process whether or not
|
|
|
|
# --nodaemon is specified. (As on Unix, --nodaemon does have the side effect
|
|
|
|
# of causing us to log to stdout/stderr.)
|
|
|
|
|
|
|
|
if "--nodaemon" in twistd_args or sys.platform == "win32":
|
|
|
|
verb = "running"
|
2008-02-18 07:28:17 +00:00
|
|
|
else:
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
verb = "starting"
|
2007-11-01 22:28:50 +00:00
|
|
|
|
2015-01-30 00:04:11 +00:00
|
|
|
print >>out, "%s node in %s" % (verb, quoted_basedir)
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
twistd.runApp(twistd_config)
|
|
|
|
# we should only reach here if --nodaemon or equivalent was used
|
|
|
|
return 0
|
2007-07-11 02:05:18 +00:00
|
|
|
|
2010-11-27 08:38:09 +00:00
|
|
|
def stop(config, out=sys.stdout, err=sys.stderr):
|
|
|
|
basedir = config['basedir']
|
2015-01-30 00:04:11 +00:00
|
|
|
quoted_basedir = quote_local_unicode_path(basedir)
|
|
|
|
print >>out, "STOPPING", quoted_basedir
|
|
|
|
pidfile = os.path.join(basedir, u"twistd.pid")
|
2007-07-11 02:05:18 +00:00
|
|
|
if not os.path.exists(pidfile):
|
2015-01-30 00:04:11 +00:00
|
|
|
print >>err, "%s does not look like a running node directory (no twistd.pid)" % quoted_basedir
|
2009-02-26 02:52:45 +00:00
|
|
|
# we define rc=2 to mean "nothing is running, but it wasn't me who
|
|
|
|
# stopped it"
|
2007-07-11 02:05:18 +00:00
|
|
|
return 2
|
|
|
|
pid = open(pidfile, "r").read()
|
|
|
|
pid = int(pid)
|
|
|
|
|
2007-10-29 18:43:35 +00:00
|
|
|
# kill it hard (SIGKILL), delete the twistd.pid file, then wait for the
|
2008-12-30 08:20:22 +00:00
|
|
|
# process itself to go away. If it hasn't gone away after 20 seconds, warn
|
2007-10-29 18:43:35 +00:00
|
|
|
# the user but keep waiting until they give up.
|
2007-08-09 15:57:45 +00:00
|
|
|
try:
|
2007-10-29 18:43:35 +00:00
|
|
|
os.kill(pid, signal.SIGKILL)
|
2007-08-09 15:57:45 +00:00
|
|
|
except OSError, oserr:
|
|
|
|
if oserr.errno == 3:
|
|
|
|
print oserr.strerror
|
2007-10-29 18:43:35 +00:00
|
|
|
# the process didn't exist, so wipe the pid file
|
|
|
|
os.remove(pidfile)
|
2009-02-26 02:52:45 +00:00
|
|
|
return 2
|
2007-08-09 15:57:45 +00:00
|
|
|
else:
|
|
|
|
raise
|
2007-10-29 18:43:35 +00:00
|
|
|
try:
|
|
|
|
os.remove(pidfile)
|
|
|
|
except EnvironmentError:
|
|
|
|
pass
|
|
|
|
start = time.time()
|
2007-07-11 02:05:18 +00:00
|
|
|
time.sleep(0.1)
|
2009-01-06 14:51:06 +00:00
|
|
|
wait = 40
|
2007-10-29 18:43:35 +00:00
|
|
|
first_time = True
|
|
|
|
while True:
|
|
|
|
# poll once per second until we see the process is no longer running
|
2007-07-11 02:05:18 +00:00
|
|
|
try:
|
|
|
|
os.kill(pid, 0)
|
|
|
|
except OSError:
|
|
|
|
print >>out, "process %d is dead" % pid
|
|
|
|
return
|
2007-10-29 18:43:35 +00:00
|
|
|
wait -= 1
|
|
|
|
if wait < 0:
|
|
|
|
if first_time:
|
|
|
|
print >>err, ("It looks like pid %d is still running "
|
|
|
|
"after %d seconds" % (pid,
|
|
|
|
(time.time() - start)))
|
|
|
|
print >>err, "I will keep watching it until you interrupt me."
|
|
|
|
wait = 10
|
|
|
|
first_time = False
|
|
|
|
else:
|
|
|
|
print >>err, "pid %d still running after %d seconds" % \
|
|
|
|
(pid, (time.time() - start))
|
|
|
|
wait = 10
|
2007-07-11 02:05:18 +00:00
|
|
|
time.sleep(1)
|
2009-02-26 02:52:45 +00:00
|
|
|
# we define rc=1 to mean "I think something is still running, sorry"
|
2007-07-11 02:05:18 +00:00
|
|
|
return 1
|
|
|
|
|
|
|
|
def restart(config, stdout, stderr):
|
2010-11-27 08:38:09 +00:00
|
|
|
rc = stop(config, stdout, stderr)
|
2009-02-25 04:42:13 +00:00
|
|
|
if rc == 2:
|
2007-07-11 02:05:18 +00:00
|
|
|
print >>stderr, "ignoring couldn't-stop"
|
|
|
|
rc = 0
|
|
|
|
if rc:
|
|
|
|
print >>stderr, "not restarting"
|
|
|
|
return rc
|
2010-11-27 08:38:09 +00:00
|
|
|
return start(config, stdout, stderr)
|
2007-07-11 02:05:18 +00:00
|
|
|
|
2008-01-10 02:54:12 +00:00
|
|
|
def run(config, stdout, stderr):
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
config.twistd_args = config.twistd_args + ("--nodaemon",)
|
|
|
|
# Previously we would do the equivalent of adding ("--logfile", "tahoesvc.log"),
|
|
|
|
# but that redirects stdout/stderr which is often unhelpful, and the user can
|
|
|
|
# add that option explicitly if they want.
|
2010-08-03 08:54:16 +00:00
|
|
|
|
'tahoe start': stop using the contents of .tac files
Instead of constructing a sys.argv for 'twistd' that reads the node's
.tac file, we construct arguments that tell twistd to use a special
in-memory-only plugin that creates the desired node instance directly.
We still use the name of the .tac file to decide which kind of instance
to make (Client, IntroducerNode, KeyGenerator, StatsGatherer), but never
actually read the contents of the .tac file. Later improvements could
change this to look inside the tahoe.cfg for a nodetype= directive, etc.
This also makes it easy to have "tahoe start BASEDIR" pass the rest of
its arguments on to twistd, so e.g. "tahoe start BASEDIR --nodaemon
--profile=prof.out" does what you'd expect "twistd --nodaemon
--profile=prof.out" to do. "tahoe run BASEDIR" is thus simply aliased to
"tahoe start BASEDIR --nodaemon". This removes the need to special-case
--profile and --syslog.
I also removed some of the default logging behavior:
before:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
'tahoe start --profile' adds '--profile=profiling_results.prof --savestats'
'tahoe run' = 'twistd --nodaemon --logfile BASEDIR/logs/tahoesvc.log'
after:
'tahoe start' = 'twistd --logfile BASEDIR logs/twistd.log'
unless --logfile, --nodaemon, or --syslog are passed
'tahoe start --profile' invalid, use 'tahoe start --profile=OUTPUT'
'tahoe run' = 'twistd --nodaemon'
so log messages go to stdout
This finally enables 'tahoe run' to work with all node types, including
the key-generator and stats-gatherer.
It gets 'tahoe start' one step closer to accepting --reactor= . To
actually accomplish this will require this file, the enclosing
__init_.py files, and everything they import to avoid importing the
reactor. (if anything imports twisted.internet.reactor before
startstop_node.start() gets to run, then --reactor= comes too late).
That will take a lot of work, and requires lazy-loading of many core
libraries (foolscap.logging in particular), and removing a lot of code
from src/allmydata/__init__.py .
2012-05-23 07:19:27 +00:00
|
|
|
return start(config, stdout, stderr)
|
2008-01-10 02:54:12 +00:00
|
|
|
|
2007-07-11 02:05:18 +00:00
|
|
|
|
|
|
|
subCommands = [
|
|
|
|
["start", None, StartOptions, "Start a node (of any type)."],
|
|
|
|
["stop", None, StopOptions, "Stop a node."],
|
|
|
|
["restart", None, RestartOptions, "Restart a node."],
|
2008-01-10 02:54:12 +00:00
|
|
|
["run", None, RunOptions, "Run a node synchronously."],
|
2007-07-11 02:05:18 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
dispatch = {
|
|
|
|
"start": start,
|
|
|
|
"stop": stop,
|
|
|
|
"restart": restart,
|
2008-01-10 02:54:12 +00:00
|
|
|
"run": run,
|
2007-07-11 02:05:18 +00:00
|
|
|
}
|