From 7c35f010730ea906ecf607dc3ac822935eb9d09d Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@allmydata.com>
Date: Wed, 25 Feb 2009 19:52:45 -0700
Subject: [PATCH] startstop_node.py: when restarting, tolerate a stale pid too

---
 src/allmydata/scripts/startstop_node.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/allmydata/scripts/startstop_node.py b/src/allmydata/scripts/startstop_node.py
index a6f4e239..3cfc0845 100644
--- a/src/allmydata/scripts/startstop_node.py
+++ b/src/allmydata/scripts/startstop_node.py
@@ -111,6 +111,8 @@ def do_stop(basedir, out=sys.stdout, err=sys.stderr):
     pidfile = os.path.join(basedir, "twistd.pid")
     if not os.path.exists(pidfile):
         print >>err, "%s does not look like a running node directory (no twistd.pid)" % basedir
+        # we define rc=2 to mean "nothing is running, but it wasn't me who
+        # stopped it"
         return 2
     pid = open(pidfile, "r").read()
     pid = int(pid)
@@ -125,7 +127,7 @@ def do_stop(basedir, out=sys.stdout, err=sys.stderr):
             print oserr.strerror
             # the process didn't exist, so wipe the pid file
             os.remove(pidfile)
-            return 1
+            return 2
         else:
             raise
     try:
@@ -157,6 +159,7 @@ def do_stop(basedir, out=sys.stdout, err=sys.stderr):
                       (pid, (time.time() - start))
                 wait = 10
         time.sleep(1)
+    # we define rc=1 to mean "I think something is still running, sorry"
     return 1
 
 def start(config, stdout, stderr):
-- 
2.45.2