changeset 499:4a8a1e886a8c

add --hup
author Matt Johnston <matt@ucc.asn.au>
date Fri, 07 Mar 2014 20:35:19 +0800
parents ccc2915b2dd9
children 136b1343e640
files py/tempserver.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/py/tempserver.py	Tue Mar 04 22:12:29 2014 +0800
+++ b/py/tempserver.py	Fri Mar 07 20:35:19 2014 +0800
@@ -108,12 +108,23 @@
     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()
+        if do_hup:
+            try:
+                os.kill(pid, signal.SIGHUP)
+                print>>sys.stderr, "Sent SIGHUP to process %d" % pid
+                sys.exit(0)
+            except OSError:
+                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:
@@ -141,6 +152,10 @@
             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')
         logf = open(logpath, 'a+')