From 850ccd41924b3e747064dff79c5d73cd47d88cc7 Mon Sep 17 00:00:00 2001 From: Nikhil Manchanda Date: Tue, 2 Jul 2013 14:42:19 -0700 Subject: [PATCH] Restore should use pgrep instead of mysqladmin to check for mysql down For a short window, while mysql is shutting down, it stops accepting network connections but the mysqld process is still alive. During this window mysqladmin ping reports that mysql is down and trying to start mysql fails with: "mysqld_safe A mysqld process already exists" Use pgrep (during restore) instead of mysqladmin ping to check mysql is down to fix this. Fixes bug: 1197161 Change-Id: Id8b8e15b4b6136c8acbc3cac17691a65a1a4ed14 --- trove/guestagent/strategies/restore/base.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/trove/guestagent/strategies/restore/base.py b/trove/guestagent/strategies/restore/base.py index d824b523f6..efe44ddb77 100644 --- a/trove/guestagent/strategies/restore/base.py +++ b/trove/guestagent/strategies/restore/base.py @@ -38,20 +38,31 @@ FLUSH PRIVILEGES; """ -def mysql_is_running(): +def exec_with_root_helper(*cmd): try: out, err = utils.execute_with_timeout( - "/usr/bin/mysqladmin", - "ping", run_as_root=True, root_helper="sudo") - LOG.info("The mysqld daemon is up and running.") + *cmd, run_as_root=True, root_helper="sudo") return True except exception.ProcessExecutionError: + return False + + +def mysql_is_running(): + if exec_with_root_helper("/usr/bin/mysqladmin", "ping"): + LOG.info("The mysqld daemon is up and running.") + return True + else: LOG.info("The mysqld daemon is not running.") return False def mysql_is_not_running(): - return not mysql_is_running() + if exec_with_root_helper("/usr/bin/pgrep", "mysqld"): + LOG.info("The mysqld daemon is still running.") + return False + else: + LOG.info("The mysqld daemon is not running.") + return True def poll_until_then_raise(event, exception):