[tor-commits] [ooni-probe/master] Check for all the possible pid file locations when checking status of ooniprobe-agent

art at torproject.org art at torproject.org
Mon Sep 19 12:14:24 UTC 2016


commit bb7bcdd18d6a94097cf4de057c752828cfdf16c6
Author: Arturo Filastò <arturo at filasto.net>
Date:   Thu Sep 1 17:29:23 2016 +0200

    Check for all the possible pid file locations when checking status of ooniprobe-agent
    
    * This fixes https://github.com/TheTorProject/ooni-probe/issues/597
---
 ooni/scripts/ooniprobe_agent.py | 41 ++++++++++++++++++++++++-----------------
 ooni/settings.py                |  8 ++++++++
 setup.py                        | 14 ++++++--------
 3 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/ooni/scripts/ooniprobe_agent.py b/ooni/scripts/ooniprobe_agent.py
index 08fba89..ecfe7d8 100644
--- a/ooni/scripts/ooniprobe_agent.py
+++ b/ooni/scripts/ooniprobe_agent.py
@@ -67,6 +67,11 @@ def start_agent(options=None):
     twistd_config.loadedPlugins = {
         "StartOoniprobeAgent": StartOoniprobeAgentPlugin()
     }
+
+    if status_agent() == 0:
+        print("Stop ooniprobe-agent before attempting to start it")
+        return 1
+
     print("Starting ooniprobe agent.")
     WEB_UI_URL = "http://{0}:{1}".format(
         config.advanced.webui_address, config.advanced.webui_port)
@@ -76,23 +81,25 @@ def start_agent(options=None):
     return 0
 
 def status_agent():
-    pidfile = os.path.join(
-        config.running_path,
-        'twistd.pid'
-    )
-    if not os.path.exists(pidfile):
-        print("ooniprobe-agent is NOT running")
-        return  1
-    pid = open(pidfile, "r").read()
-    pid = int(pid)
-    try:
-        os.kill(pid, signal.SIG_DFL)
-    except OSError, oserr:
-        if oserr.errno == 3:
-            print("ooniprobe-agent is NOT running")
-            return 1
-    print("ooniprobe-agent is running")
-    return 0
+    running = False
+    for pidfile in [config.system_pid_path, config.user_pid_path]:
+        if not os.path.exists(pidfile):
+            # Didn't find the pid_file
+            continue
+        pid = open(pidfile, "r").read()
+        pid = int(pid)
+        try:
+            os.kill(pid, signal.SIG_DFL)
+            running = True
+        except OSError, oserr:
+            if oserr.errno == 3:
+                # Found pid, but isn't running
+                continue
+    if running is True:
+        print("ooniprobe-agent is running")
+        return 0
+    print("ooniprobe-agent is NOT running")
+    return 1
 
 def stop_agent():
     # This function is borrowed from tahoe
diff --git a/ooni/settings.py b/ooni/settings.py
index c36f3f7..065252b 100644
--- a/ooni/settings.py
+++ b/ooni/settings.py
@@ -235,6 +235,14 @@ class OConfig(object):
         return self.ooni_home
 
     @property
+    def user_pid_path(self):
+        return os.path.join(self.ooni_home, "twistd.pid")
+
+    @property
+    def system_pid_path(self):
+        return os.path.join(VAR_LIB_PATH, "twistd.pid")
+
+    @property
     def data_directory_candidates(self):
         dirs = [
             self.ooni_home,
diff --git a/setup.py b/setup.py
index 7612b39..e5dd836 100644
--- a/setup.py
+++ b/setup.py
@@ -69,19 +69,17 @@ When you got them run:
 Using ooniprobe
 ---------------
 
-To generate a test deck for your country, cd to the directory where you want it
-and run:
+It is recommended that you start the ooniprobe-agent system daemon that will
+expose a localhost only Web UI and automatically run tests for you.
 
-.. code:: bash
-
-    oonideckgen
+This can be done with:
 
+.. code:: bash
 
-To setup a daily cronjob run this:
+    ooniprobe-agent start
 
-.. code:: bash
 
-    (crontab -l 2>/dev/null; echo "@daily ooniprobe `oonideckgen | grep -e '^ooniprobe'`") | crontab -
+Then connect to the local web interface on http://127.0.0.1:8842/
 
 Have fun!
 """





More information about the tor-commits mailing list