Ticket #1262: start-m.diff

File start-m.diff, 2.0 KB (added by warner, at 2010-11-17T22:50:39Z)

preliminary patch: use fork() to start/restart all nodes but the last

  • src/allmydata/scripts/startstop_node.py

    diff --git a/src/allmydata/scripts/startstop_node.py b/src/allmydata/scripts/startstop_node.py
    index bc2616e..467f42e 100644
    a b class RunOptions(BasedirMixin, BaseOptions): 
    2929        ["multiple", "m", None, "['tahoe run' cannot accept multiple node directories]"],
    3030    ]
    3131
    32 def do_start(basedir, opts, out=sys.stdout, err=sys.stderr):
     32def do_start(basedir, opts, out=sys.stdout, err=sys.stderr, fork=False):
    3333    print >>out, "STARTING", quote_output(basedir)
    3434    if not os.path.isdir(basedir):
    3535        print >>err, "%s does not look like a directory at all" % quote_output(basedir)
    def do_start(basedir, opts, out=sys.stdout, err=sys.stderr): 
    5757    if opts["profile"]:
    5858        args.extend(["--profile=profiling_results.prof", "--savestats",])
    5959    # now we're committed
     60    if fork:
     61        if os.fork() != 0:
     62            return 0 # parent
     63        # we're in the child
    6064    os.chdir(basedir)
    6165    from twisted.scripts import twistd
    6266    sys.argv = args
    def do_stop(basedir, out=sys.stdout, err=sys.stderr): 
    123127
    124128def start(config, stdout, stderr):
    125129    rc = 0
    126     for basedir in config['basedirs']:
    127         rc = do_start(basedir, config, stdout, stderr) or rc
     130    for basedir in config['basedirs'][:-1]:
     131        # fork before starting all but the last one
     132        rc = do_start(basedir, config, stdout, stderr, fork=True) or rc
     133    # start the last one in the current process, to capture its exit code
     134    rc = do_start(config['basedirs'][-1], config, stdout, stderr, fork=False) or rc
    128135    return rc
    129136
    130137def stop(config, stdout, stderr):
    def restart(config, stdout, stderr): 
    143150    if rc:
    144151        print >>stderr, "not restarting"
    145152        return rc
    146     for basedir in config['basedirs']:
    147         rc = do_start(basedir, config, stdout, stderr) or rc
     153    rc = start(config, stdout, stderr) or rc
    148154    return rc
    149155
    150156def run(config, stdout, stderr):