# HG changeset patch # User Matt Johnston # Date 1395665340 -28800 # Node ID 136b1343e6400f9eb4c2d4a611fcfa885e5634ee # Parent 88204c0db5fa693f858594c70b7235256c1dad37# Parent 4a8a1e886a8c457ce1e92a3c98160c54a21aab7b merge diff -r 88204c0db5fa -r 136b1343e640 py/fridge.py --- a/py/fridge.py Mon Mar 24 20:48:28 2014 +0800 +++ b/py/fridge.py Mon Mar 24 20:49:00 2014 +0800 @@ -83,9 +83,8 @@ # handle broken wort sensor if wort is None: - self.wort_valid_clock = self.server.now() - W("Invalid wort sensor") invalid_time = self.server.now() - self.wort_valid_clock + W("Invalid wort sensor for %d secs" % invalid_time) if invalid_time < config.FRIDGE_WORT_INVALID_TIME: W("Has only been invalid for %d, waiting" % invalid_time) return diff -r 88204c0db5fa -r 136b1343e640 py/tempserver.py --- a/py/tempserver.py Mon Mar 24 20:48:28 2014 +0800 +++ b/py/tempserver.py Mon Mar 24 20:49:00 2014 +0800 @@ -3,6 +3,8 @@ import sys import os import logging +import time +import signal import gevent import gevent.monkey @@ -106,21 +108,53 @@ heredir = os.path.abspath(os.path.dirname(__file__)) pidpath = os.path.join(heredir, 'tempserver.pid') pidf = lockfile.pidlockfile.PIDLockFile(pidpath, threaded=False) + do_hup = '--hup' in sys.argv try: pidf.acquire(0) pidf.release() except lockfile.AlreadyLocked, e: pid = pidf.read_pid() - print>>sys.stderr, "Locked by PID %d" % pid - if pid > 0: + if do_hup: try: - os.kill(pid, 0) - # must still be running PID - raise e + os.kill(pid, signal.SIGHUP) + print>>sys.stderr, "Sent SIGHUP to process %d" % pid + sys.exit(0) except OSError: - # isn't still running, steal the lock - print>>sys.stderr, "Unlinking stale lockfile %s for pid %d" % (pidpath, pid) - pidf.break_lock() + print>>sys.stderr, "Process %d isn't running?" % pid + sys.exit(1) + + print>>sys.stderr, "Locked by PID %d" % pid + + stale = False + if pid > 0: + if '--new' in sys.argv: + try: + os.kill(pid, 0) + except OSError: + stale = True + + if not stale: + print>>sys.stderr, "Stopping old tempserver pid %d" % pid + os.kill(pid, signal.SIGTERM) + time.sleep(2) + pidf.acquire(0) + pidf.release() + else: + try: + os.kill(pid, 0) + # must still be running PID + raise e + except OSError: + stale = True + + if stale: + # isn't still running, steal the lock + print>>sys.stderr, "Unlinking stale lockfile %s for pid %d" % (pidpath, pid) + pidf.break_lock() + + if do_hup: + print>>sys.stderr, "Doesn't seem to be running" + sys.exit(1) if '--daemon' in sys.argv: logpath = os.path.join(os.path.dirname(__file__), 'tempserver.log')