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
This commit is contained in:
Matthew Jones 2015-07-06 14:15:41 -04:00
parent 10f5308bd8
commit 9b03d22d75

View File

@ -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))