From c8ef4a1b89b5591fec295e8e706e58a67ee8e971 Mon Sep 17 00:00:00 2001 From: Ben Patterson Date: Thu, 31 Jul 2014 14:49:38 -0400 Subject: [PATCH] Bok-choy: check if mysql is running, even if it's not a daemon. The impetus is integration with test environments, where mysql is not configured as a service. --- pavelib/utils/test/bokchoy_utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pavelib/utils/test/bokchoy_utils.py b/pavelib/utils/test/bokchoy_utils.py index 368a96ea60..c71c6164aa 100644 --- a/pavelib/utils/test/bokchoy_utils.py +++ b/pavelib/utils/test/bokchoy_utils.py @@ -5,6 +5,7 @@ import sys import os import time import httplib +import subprocess from paver.easy import sh from pavelib.utils.envs import Env from pavelib.utils.process import run_background_process @@ -125,10 +126,12 @@ def is_mysql_running(): """ Returns True if mysql is running, False otherwise. """ - # We use the MySQL CLI client and capture its stderr - # If the client cannot connect successfully, stderr will be non-empty - output = os.popen('status mysql 2>&1').read() - return output.startswith("mysql start/running, process") + # We need to check whether or not mysql is running as a process + # even if it is not daemonized. + with open(os.devnull, 'w') as DEVNULL: + #pgrep returns the PID, which we send to /dev/null + returncode = subprocess.call("pgrep mysqld", stdout=DEVNULL, shell=True) + return returncode == 0 def clear_mongo():