From 8f4f3bf6cc20f9644e42ec9a992743dc14e96593 Mon Sep 17 00:00:00 2001 From: robk-tahoe Date: Wed, 9 Jan 2008 19:54:12 -0700 Subject: [PATCH] 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. --- src/allmydata/scripts/startstop_node.py | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/allmydata/scripts/startstop_node.py b/src/allmydata/scripts/startstop_node.py index e3d37981..1b8bf495 100644 --- a/src/allmydata/scripts/startstop_node.py +++ b/src/allmydata/scripts/startstop_node.py @@ -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, } -- 2.45.2