changeset 201:159b0e77ab21

merge
author Matt Johnston <matt@ucc.asn.au>
date Mon, 24 Mar 2014 20:49:00 +0800
parents 1d8a8bd2ea78 (current diff) 2affbaae408b (diff)
children 6dd157a12035
files
diffstat 2 files changed, 43 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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')