aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Finkel <Matthew.Finkel@gmail.com>2013-11-13 23:27:31 +0000
committerMatthew Finkel <Matthew.Finkel@gmail.com>2013-11-13 23:27:31 +0000
commitfad78679d34e4f345b13942e9bbdc0ddbbb52e13 (patch)
treebc540ace5bcaf046cf3debbe4c3b94d019d78108
parenta8fd93126493b2f081984131cc0837803fd4b1a4 (diff)
downloadchutney-fad78679d34e4f345b13942e9bbdc0ddbbb52e13.tar
chutney-fad78679d34e4f345b13942e9bbdc0ddbbb52e13.tar.gz
Allow nodes to be started after a specified time
-rw-r--r--lib/chutney/TorNet.py46
1 files changed, 39 insertions, 7 deletions
diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py
index 792056a..57b8632 100644
--- a/lib/chutney/TorNet.py
+++ b/lib/chutney/TorNet.py
@@ -187,6 +187,7 @@ class LocalNodeBuilder(NodeBuilder):
# fingerprint -- used only if authority
# dirserver_flags -- used only if authority
# nick -- nickname of this router
+ # delay -- seconds before launching node
## Environment members set
# fingerprint -- hex router key fingerprint
@@ -448,15 +449,44 @@ class LocalNodeController(NodeController):
"--quiet",
"-f", torrc,
]
- p = subprocess.Popen(cmdline)
- # XXXX this requires that RunAsDaemon is set.
- p.wait()
- if p.returncode != 0:
- print "Couldn't launch %s (%s): %s"%(self._env['nick'],
+ forkPid = -1
+ noDelay = isChild = isParent = False
+ if self._env['delay']:
+ try:
+ forkPid = os.fork()
+ if forkPid == 0:
+ isChild = True
+ time.sleep(self._env['delay'])
+ else:
+ isParent = True
+
+ except OSError, e:
+ print "Could not delay launch of %s (%s): %s"%(self._env['nick'],
+ " ".join(cmdline),
+ e.strerror())
+ return False
+ else:
+ noDelay = True
+
+ retval = True
+ if noDelay or isChild:
+ p = subprocess.Popen(cmdline)
+ # XXXX this requires that RunAsDaemon is set.
+ p.wait()
+ if p.returncode != 0:
+ print "Couldn't launch %s (%s): %s"%(self._env['nick'],
" ".join(cmdline),
p.returncode)
- return False
- return True
+ retval = True
+ if isChild:
+ print "Launching %s after %d seconds" % (self._env['nick'],
+ self._env['delay'])
+ sys.exit(retval)
+ elif isParent:
+ print "Delaying launch of %s for %d seconds"%(self._env['nick'],
+ self._env['delay'])
+ return retval
+
def stop(self, sig=signal.SIGINT):
"""Try to stop this node by sending it the signal 'sig'."""
@@ -491,6 +521,7 @@ DEFAULTS = {
'authorities' : "AlternateDirAuthority bleargh bad torrc file!",
'bridges' : "Bridge bleargh bad torrc file!",
'core' : True,
+ 'delay' : 0,
}
class TorEnviron(chutney.Templating.Environ):
@@ -605,6 +636,7 @@ class Network(object):
def start(self):
print "Starting nodes"
+ self._dfltEnv['start_time'] = time.time()
return all([n.getController().start() for n in self._nodes])
def hup(self):