mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-11 21:45:34 +00:00
check_memory.py: finish the failsafe-shutdown code
This commit is contained in:
parent
4c7c5df41e
commit
c405c6117f
@ -173,7 +173,7 @@ count-lines:
|
|||||||
@echo -n "TODO: "
|
@echo -n "TODO: "
|
||||||
@grep TODO `find src -name '*.py' |grep -v /build/` | wc --lines
|
@grep TODO `find src -name '*.py' |grep -v /build/` | wc --lines
|
||||||
|
|
||||||
check-memory:
|
check-memory: build
|
||||||
$(PP) $(PYTHON) src/allmydata/test/check_memory.py
|
$(PP) $(PYTHON) src/allmydata/test/check_memory.py
|
||||||
|
|
||||||
test-darcs-boringfile:
|
test-darcs-boringfile:
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
|
|
||||||
import os, sha
|
import os, sha, stat, time
|
||||||
from foolscap import Referenceable
|
from foolscap import Referenceable
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
from allmydata.interfaces import RIClient
|
from allmydata.interfaces import RIClient
|
||||||
from allmydata import node
|
from allmydata import node
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer, reactor
|
||||||
|
from twisted.application.internet import TimerService
|
||||||
|
|
||||||
import allmydata
|
import allmydata
|
||||||
from allmydata.Crypto.Util.number import bytes_to_long
|
from allmydata.Crypto.Util.number import bytes_to_long
|
||||||
@ -25,6 +26,7 @@ class Client(node.Node, Referenceable):
|
|||||||
WEBPORTFILE = "webport"
|
WEBPORTFILE = "webport"
|
||||||
INTRODUCER_FURL_FILE = "introducer.furl"
|
INTRODUCER_FURL_FILE = "introducer.furl"
|
||||||
GLOBAL_VDRIVE_FURL_FILE = "vdrive.furl"
|
GLOBAL_VDRIVE_FURL_FILE = "vdrive.furl"
|
||||||
|
SUICIDE_PREVENTION_HOTLINE_FILE = "suicide_prevention_hotline"
|
||||||
|
|
||||||
# we're pretty narrow-minded right now
|
# we're pretty narrow-minded right now
|
||||||
OLDEST_SUPPORTED_VERSION = allmydata.__version__
|
OLDEST_SUPPORTED_VERSION = allmydata.__version__
|
||||||
@ -57,6 +59,20 @@ class Client(node.Node, Referenceable):
|
|||||||
self.global_vdrive_furl = f.read().strip()
|
self.global_vdrive_furl = f.read().strip()
|
||||||
f.close()
|
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):
|
def tub_ready(self):
|
||||||
self.log("tub_ready")
|
self.log("tub_ready")
|
||||||
self.my_furl = self.tub.registerReference(self)
|
self.my_furl = self.tub.registerReference(self)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
import os, shutil
|
import os, shutil
|
||||||
|
|
||||||
from twisted.internet import defer, reactor, protocol, error
|
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 import client, introducer_and_vdrive
|
||||||
from allmydata.scripts import runner
|
from allmydata.scripts import runner
|
||||||
from foolscap.eventual import eventually, flushEventualQueue
|
from foolscap.eventual import eventually, flushEventualQueue
|
||||||
@ -57,9 +57,10 @@ class SystemFramework:
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
def make_introducer_and_vdrive(self):
|
def make_introducer_and_vdrive(self):
|
||||||
introducer_and_vdrive_dir = os.path.join(self.basedir, "introducer_and_vdrive")
|
iv_basedir = os.path.join(self.basedir, "introducer_and_vdrive")
|
||||||
os.mkdir(introducer_and_vdrive_dir)
|
os.mkdir(iv_basedir)
|
||||||
self.introducer_and_vdrive = self.add_service(introducer_and_vdrive.IntroducerAndVdrive(basedir=introducer_and_vdrive_dir))
|
iv = introducer_and_vdrive.IntroducerAndVdrive(basedir=iv_basedir)
|
||||||
|
self.introducer_and_vdrive = self.add_service(iv)
|
||||||
d = self.introducer_and_vdrive.when_tub_ready()
|
d = self.introducer_and_vdrive.when_tub_ready()
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@ -84,25 +85,33 @@ class SystemFramework:
|
|||||||
|
|
||||||
def touch_keepalive(self):
|
def touch_keepalive(self):
|
||||||
f = open(self.keepalive_file, "w")
|
f = open(self.keepalive_file, "w")
|
||||||
f.write("If the node notices this file at startup, it will poll and\n")
|
f.write("""\
|
||||||
f.write("terminate as soon as the file goes away. This prevents\n")
|
If the node notices this file at startup, it will poll every 5 seconds and
|
||||||
f.write("leaving processes around if the test harness has an\n")
|
terminate if the file is more than 10 seconds old, or if it has been deleted.
|
||||||
f.write("internal failure and neglects to kill off the node\n")
|
If the test harness has an internal failure and neglects to kill off the node
|
||||||
f.write("itself. The contents of this file are ignored.\n")
|
itself, this helps to avoid leaving processes lying around. The contents of
|
||||||
|
this file are ignored.
|
||||||
|
""")
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def start_client(self):
|
def start_client(self):
|
||||||
log.msg("MAKING CLIENT")
|
log.msg("MAKING CLIENT")
|
||||||
clientdir = self.clientdir = os.path.join(self.basedir, "client")
|
clientdir = self.clientdir = os.path.join(self.basedir, "client")
|
||||||
config = {'basedir': clientdir}
|
config = {'basedir': clientdir, 'quiet': False}
|
||||||
runner.create_client(config)
|
runner.create_client(config)
|
||||||
log.msg("DONE MAKING CLIENT")
|
log.msg("DONE MAKING CLIENT")
|
||||||
f = open(os.path.join(clientdir, "introducer.furl"), "w")
|
f = open(os.path.join(clientdir, "introducer.furl"), "w")
|
||||||
f.write(self.introducer_furl + "\n")
|
f.write(self.introducer_furl + "\n")
|
||||||
f.close()
|
f.close()
|
||||||
self.keepalive_file = os.path.join(clientdir, "suicide_prevention_hotline")
|
f = open(os.path.join(clientdir, "vdrive.furl"), "w")
|
||||||
self.touch_keepalive()
|
f.write(self.introducer_furl + "\n")
|
||||||
|
f.close()
|
||||||
|
self.keepalive_file = os.path.join(clientdir,
|
||||||
|
"suicide_prevention_hotline")
|
||||||
# now start updating the mtime.
|
# now start updating the mtime.
|
||||||
|
self.touch_keepalive()
|
||||||
|
ts = internet.TimerService(4.0, self.touch_keepalive)
|
||||||
|
ts.setServiceParent(self.sparent)
|
||||||
|
|
||||||
pp = ClientWatcher()
|
pp = ClientWatcher()
|
||||||
cmd = ["twistd", "-y", "client.tac"]
|
cmd = ["twistd", "-y", "client.tac"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user