From 9b03d22d75acf1142c3fb31ca8c87a87c55ce2ff Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Mon, 6 Jul 2015 14:15:41 -0400 Subject: [PATCH] Fixes to conditionally invoking mongo shutdown * Make sure we are waiting on the service script * Improve sudo configuration * Check pidof before attempting to invoke a hard mongo shutdown --- awx/main/tasks.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 800225e02f..90eddb1ab4 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -133,14 +133,19 @@ def mongodb_control(cmd): p = subprocess.Popen('sudo service mongod %s' % cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() + p.wait() + + # Check to make sure the stop actually succeeded + p = subprocess.Popen('pidof mongod', shell=True) + shutdown_failed = p.wait() == 1 # If there was an error, log it. if err: logger.error(err) - if cmd == 'stop': + if cmd == 'stop' and shutdown_failed: time.sleep(30) - p = subprocess.Popen('sudo mongod --shutdown -f /etc/mongod.conf') + p = subprocess.Popen('sudo mongod --shutdown -f /etc/mongod.conf', shell=True) out, err = p.communicate() logger.info("Shutdown command output: %s;%s" % (out, err))