import os, sys, signal, time
-from allmydata.scripts.common import BasedirMixin, BaseOptions
+from allmydata.scripts.common import BasedirOptions
from allmydata.util import fileutil
from allmydata.util.assertutil import precondition
from allmydata.util.encodingutil import listdir_unicode, quote_output
-class StartOptions(BasedirMixin, BaseOptions):
+
+class StartOptions(BasedirOptions):
optFlags = [
["profile", "p", "Run under the Python profiler, putting results in 'profiling_results.prof'."],
["syslog", None, "Tell the node to log to syslog, not a file."],
]
-class StopOptions(BasedirMixin, BaseOptions):
- pass
+ def getSynopsis(self):
+ return "Usage: %s [global-opts] start [options] [NODEDIR]" % (self.command_name,)
+
+
+class StopOptions(BasedirOptions):
+ def getSynopsis(self):
+ return "Usage: %s [global-opts] stop [options] [NODEDIR]" % (self.command_name,)
-class RestartOptions(BasedirMixin, BaseOptions):
+
+class RestartOptions(BasedirOptions):
optFlags = [
["profile", "p", "Run under the Python profiler, putting results in 'profiling_results.prof'."],
["syslog", None, "Tell the node to log to syslog, not a file."],
]
-class RunOptions(BasedirMixin, BaseOptions):
+ def getSynopsis(self):
+ return "Usage: %s [global-opts] restart [options] [NODEDIR]" % (self.command_name,)
+
+
+class RunOptions(BasedirOptions):
default_nodedir = u"."
- allow_multiple = False
- optParameters = [
- ["node-directory", "d", None, "Specify the directory of the node to be run. [default, for 'tahoe run' only: current directory]"],
- ]
- optFlags = [ ]
- if BasedirMixin.can_start_multiple:
- # usage.Options doesn't let us remove flags that we inherit from a
- # parent class, so at least provide a --help string that warns people
- # away from using it. There is also code (switching on
- # allow_multiple) to disable it at runtime.
- optFlags.append(["multiple", "m",
- "['tahoe run' cannot accept multiple node directories]"])
-
-def do_start(basedir, opts, out=sys.stdout, err=sys.stderr, fork=False):
+ def getSynopsis(self):
+ return "Usage: %s [global-opts] run [options] [NODEDIR]" % (self.command_name,)
+
+
+def start(opts, out=sys.stdout, err=sys.stderr):
+ basedir = opts['basedir']
print >>out, "STARTING", quote_output(basedir)
if not os.path.isdir(basedir):
print >>err, "%s does not look like a directory at all" % quote_output(basedir)
if opts["profile"]:
args.extend(["--profile=profiling_results.prof", "--savestats",])
# now we're committed
- if fork:
- if os.fork() != 0:
- return 0 # parent
- # we're in the child
os.chdir(basedir)
from twisted.scripts import twistd
sys.argv = args
# 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):
+def stop(config, out=sys.stdout, err=sys.stderr):
+ basedir = config['basedir']
print >>out, "STOPPING", quote_output(basedir)
pidfile = os.path.join(basedir, "twistd.pid")
if not os.path.exists(pidfile):
# we define rc=1 to mean "I think something is still running, sorry"
return 1
-def start(config, stdout, stderr):
- rc = 0
- for basedir in config['basedirs'][:-1]:
- # fork before starting all but the last one
- rc = do_start(basedir, config, stdout, stderr, fork=True) or rc
- # start the last one in the current process, to capture its exit code
- rc = do_start(config['basedirs'][-1], config, stdout, stderr, fork=False) or rc
- return rc
-
-def stop(config, stdout, stderr):
- rc = 0
- for basedir in config['basedirs']:
- rc = do_stop(basedir, stdout, stderr) or rc
- return rc
-
def restart(config, stdout, stderr):
- rc = 0
- for basedir in config['basedirs']:
- rc = do_stop(basedir, stdout, stderr) or rc
+ rc = stop(config, stdout, stderr)
if rc == 2:
print >>stderr, "ignoring couldn't-stop"
rc = 0
if rc:
print >>stderr, "not restarting"
return rc
- rc = start(config, stdout, stderr) or rc
- return rc
+ return start(config, stdout, stderr)
def run(config, stdout, stderr):
from twisted.internet import reactor
from twisted.python import log, logfile
from allmydata import client
- basedir = config['basedirs'][0]
+ basedir = config['basedir']
precondition(isinstance(basedir, unicode), basedir)
if not os.path.isdir(basedir):