add 'run' command to tahoe

adds a 'run' commands to bin/tahoe / tahoe.exe
it loads a client node into the tahoe process itself,
running in the base dir specified by --basedir/-C and
defaulting to the current working dir.

it runs synchronously, and the tahoe process blocks until
the reactor is stopped.
This commit is contained in:
robk-tahoe 2008-01-09 19:54:12 -07:00
parent 330f84758e
commit 8f4f3bf6cc

View File

@ -28,6 +28,11 @@ class RestartOptions(BasedirMixin, usage.Options):
["profile", "p", "whether to run under the Python profiler, putting results in \"profiling_results.prof\""],
]
class RunOptions(usage.Options):
optParameters = [
["basedir", "C", None, "which directory to run the node in, CWD by default"],
]
def do_start(basedir, profile=False, out=sys.stdout, err=sys.stderr):
print >>out, "STARTING", basedir
if os.path.exists(os.path.join(basedir, "client.tac")):
@ -149,15 +154,42 @@ def restart(config, stdout, stderr):
rc = do_start(basedir, config['profile'], stdout, stderr) or rc
return rc
def run(config, stdout, stderr):
from twisted.internet import reactor
from twisted.python import log, logfile
from allmydata import client
basedir = config['basedir']
if basedir is None:
basedir = '.'
else:
os.chdir(basedir)
# 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(c.startService) # after reactor startup
reactor.run()
return 0
subCommands = [
["start", None, StartOptions, "Start a node (of any type)."],
["stop", None, StopOptions, "Stop a node."],
["restart", None, RestartOptions, "Restart a node."],
["run", None, RunOptions, "Run a node synchronously."],
]
dispatch = {
"start": start,
"stop": stop,
"restart": restart,
"run": run,
}