dbuscrontab: get daemon's pid from pidfile if upstart failed
authorKonstantin Stepanov <kstep@p-nut.info>
Wed, 22 Dec 2010 12:28:51 +0000 (14:28 +0200)
committerKonstantin Stepanov <kstep@p-nut.info>
Wed, 22 Dec 2010 12:28:51 +0000 (14:28 +0200)
dbuscron/shell/edit.py

index 810b7dc..607619f 100644 (file)
@@ -18,14 +18,26 @@ def run_system_editor(filename):
     if os.system(editor + ' ' + pipes.quote(filename)) != 0:
         raise SystemError('Editor returned non-zero status value.')
 
+def get_dbuscron_pid_from_upstart():
+    f = os.popen('initctl status dbuscron', 'r')
+    status = f.readline()
+    f.close()
+    return int(status.strip().split(' ').pop())
+
+def get_dbuscron_pid_from_pidfile():
+    f = open(pidfile, 'r')
+    pid = f.readline()
+    f.close()
+    return int(pid)
+
 def get_dbuscron_pid():
     try:
-        f = os.popen('initctl status dbuscron', 'r')
-        status = f.readline()
-        f.close()
-        return int(status.strip().split(' ').pop())
+        return get_dbuscron_pid_from_upstart()
     except:
-        raise SystemError('Unable to get PID of dbuscron job.')
+        try:
+            return get_dbuscron_pid_from_pidfile()
+        except:
+            raise SystemError('Unable to get PID of dbuscron job.')
 
 def check_syntax(filename):
     parser = CrontabParser(filename)