From 6b8747d2314f8654c5729509ecab9285cb530ec4 Mon Sep 17 00:00:00 2001 From: Konstantin Stepanov Date: Wed, 22 Dec 2010 14:28:51 +0200 Subject: [PATCH] dbuscrontab: get daemon's pid from pidfile if upstart failed --- dbuscron/shell/edit.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/dbuscron/shell/edit.py b/dbuscron/shell/edit.py index 810b7dc..607619f 100644 --- a/dbuscron/shell/edit.py +++ b/dbuscron/shell/edit.py @@ -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) -- 1.7.9.5