-import os, sha
+import os, sha, stat, time
from foolscap import Referenceable
from zope.interface import implements
from allmydata.interfaces import RIClient
from allmydata import node
-from twisted.internet import defer
+from twisted.internet import defer, reactor
+from twisted.application.internet import TimerService
import allmydata
from allmydata.Crypto.Util.number import bytes_to_long
WEBPORTFILE = "webport"
INTRODUCER_FURL_FILE = "introducer.furl"
GLOBAL_VDRIVE_FURL_FILE = "vdrive.furl"
+ SUICIDE_PREVENTION_HOTLINE_FILE = "suicide_prevention_hotline"
# we're pretty narrow-minded right now
OLDEST_SUPPORTED_VERSION = allmydata.__version__
self.global_vdrive_furl = f.read().strip()
f.close()
+ hotline_file = os.path.join(self.basedir,
+ self.SUICIDE_PREVENTION_HOTLINE_FILE)
+ if os.path.exists(hotline_file):
+ hotline = TimerService(5.0, self._check_hotline, hotline_file)
+ hotline.setServiceParent(self)
+
+ def _check_hotline(self, hotline_file):
+ if os.path.exists(hotline_file):
+ mtime = os.stat(hotline_file)[stat.ST_MTIME]
+ if mtime > time.time() - 10.0:
+ return
+ self.log("hotline missing or too old, shutting down")
+ reactor.stop()
+
def tub_ready(self):
self.log("tub_ready")
self.my_furl = self.tub.registerReference(self)
import os, shutil
from twisted.internet import defer, reactor, protocol, error
-from twisted.application import service
+from twisted.application import service, internet
from allmydata import client, introducer_and_vdrive
from allmydata.scripts import runner
from foolscap.eventual import eventually, flushEventualQueue
return s
def make_introducer_and_vdrive(self):
- introducer_and_vdrive_dir = os.path.join(self.basedir, "introducer_and_vdrive")
- os.mkdir(introducer_and_vdrive_dir)
- self.introducer_and_vdrive = self.add_service(introducer_and_vdrive.IntroducerAndVdrive(basedir=introducer_and_vdrive_dir))
+ iv_basedir = os.path.join(self.basedir, "introducer_and_vdrive")
+ os.mkdir(iv_basedir)
+ iv = introducer_and_vdrive.IntroducerAndVdrive(basedir=iv_basedir)
+ self.introducer_and_vdrive = self.add_service(iv)
d = self.introducer_and_vdrive.when_tub_ready()
return d
def touch_keepalive(self):
f = open(self.keepalive_file, "w")
- f.write("If the node notices this file at startup, it will poll and\n")
- f.write("terminate as soon as the file goes away. This prevents\n")
- f.write("leaving processes around if the test harness has an\n")
- f.write("internal failure and neglects to kill off the node\n")
- f.write("itself. The contents of this file are ignored.\n")
+ f.write("""\
+If the node notices this file at startup, it will poll every 5 seconds and
+terminate if the file is more than 10 seconds old, or if it has been deleted.
+If the test harness has an internal failure and neglects to kill off the node
+itself, this helps to avoid leaving processes lying around. The contents of
+this file are ignored.
+ """)
f.close()
def start_client(self):
log.msg("MAKING CLIENT")
clientdir = self.clientdir = os.path.join(self.basedir, "client")
- config = {'basedir': clientdir}
+ config = {'basedir': clientdir, 'quiet': False}
runner.create_client(config)
log.msg("DONE MAKING CLIENT")
f = open(os.path.join(clientdir, "introducer.furl"), "w")
f.write(self.introducer_furl + "\n")
f.close()
- self.keepalive_file = os.path.join(clientdir, "suicide_prevention_hotline")
- self.touch_keepalive()
+ f = open(os.path.join(clientdir, "vdrive.furl"), "w")
+ f.write(self.introducer_furl + "\n")
+ f.close()
+ self.keepalive_file = os.path.join(clientdir,
+ "suicide_prevention_hotline")
# now start updating the mtime.
+ self.touch_keepalive()
+ ts = internet.TimerService(4.0, self.touch_keepalive)
+ ts.setServiceParent(self.sparent)
pp = ClientWatcher()
cmd = ["twistd", "-y", "client.tac"]