From: Brian Warner Date: Wed, 27 Oct 2010 06:13:42 +0000 (-0700) Subject: 'tahoe start': use import+call rather than find+spawn X-Git-Tag: trac-4800~36 X-Git-Url: https://git.rkrishnan.org/vdrive/%22file:/configuration.txt?a=commitdiff_plain;h=ac3b26ecf29c08cb6342535be10b384d1ab3cf3d;p=tahoe-lafs%2Ftahoe-lafs.git 'tahoe start': use import+call rather than find+spawn This removes the need to use a locally-built (dependency) bin/twistd, and removes a big chunk of behavior differences between unix and windows. It also happens to resolve the "client node probably started" uncertainty. Might help with #1190, #602, and #71. --- diff --git a/src/allmydata/scripts/startstop_node.py b/src/allmydata/scripts/startstop_node.py index 1fe996e2..8256a1e0 100644 --- a/src/allmydata/scripts/startstop_node.py +++ b/src/allmydata/scripts/startstop_node.py @@ -48,60 +48,22 @@ def do_start(basedir, opts, out=sys.stdout, err=sys.stderr): else: nodetype = "unknown (%s)" % tac - cmd = find_exe.find_exe('twistd') - if not cmd: - # If 'twistd' wasn't on $PATH, maybe we're running from source and - # Twisted was built as one of our dependencies. If so, we're at - # BASEDIR/src/allmydata/scripts/startstop_node.py, and it's at - # BASEDIR/support/$BINDIR/twistd - up = os.path.dirname - TAHOEDIR = up(up(up(up(os.path.abspath(__file__))))) - if sys.platform == "win32": - bin_dir = "Scripts" - else: - bin_dir = "bin" - bindir = os.path.join(TAHOEDIR, "support", bin_dir) - - maybe = os.path.join(bindir, "twistd") - if os.path.exists(maybe): - cmd = [maybe] - oldpath = os.environ.get("PATH", "").split(os.pathsep) - os.environ["PATH"] = os.pathsep.join(oldpath + [bindir]) - # sys.path and $PYTHONPATH are taken care of by the extra code in - # 'setup.py trial' - else: - maybe = maybe+'.py' - if os.path.exists(maybe): - cmd = [sys.executable, maybe] - oldpath = os.environ.get("PATH", "").split(os.pathsep) - os.environ["PATH"] = os.pathsep.join(oldpath + [bindir]) - # sys.path and $PYTHONPATH are taken care of by the extra code in - # 'setup.py trial' - - if not cmd: - print "Can't find twistd (it comes with Twisted). Aborting." - sys.exit(1) - - cmd.extend(["-y", tac]) + args = ["twistd", "-y", tac] if opts["syslog"]: - cmd.append("--syslog") + args.append("--syslog") elif nodetype in ("client", "introducer"): fileutil.make_dirs(os.path.join(basedir, "logs")) - cmd.extend(["--logfile", os.path.join("logs", "twistd.log")]) + args.extend(["--logfile", os.path.join("logs", "twistd.log")]) if opts["profile"]: - cmd.extend(["--profile=profiling_results.prof", "--savestats",]) - curdir = os.getcwd() - try: - os.chdir(basedir) - rc = os.system(' '.join(cmd)) - finally: - os.chdir(curdir) - if rc == 0: - print >>out, "%s node probably started" % nodetype - return 0 - else: - print >>err, "%s node probably not started" % nodetype - return 1 + args.extend(["--profile=profiling_results.prof", "--savestats",]) + # now we're committed + os.chdir(basedir) + from twisted.scripts import twistd + sys.argv = args + twistd.run() + # run() doesn't return: the parent does os._exit(0) in daemonize(), so + # we'll never get here. If application setup fails (e.g. ImportError), + # run() will raise an exception. def do_stop(basedir, out=sys.stdout, err=sys.stderr): print >>out, "STOPPING", quote_output(basedir)