From 0965bc0dced806f51a4d4bd39642dab20dbec87e Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 30 Aug 2017 10:21:27 -0400 Subject: [PATCH] Leverage systemd for service running check With the switch to uwsgi (for most services) just doing a ps and grepping for the process name isn't as simple as it was when each binary command was unique. When using uwsgi the command is 'uwsgi' which isn't unique between processes. Luckily we've also switched everything to run under systemd which gives us an easy alternative to check if the service is running. This commit pivots the checking to leverage systemd to check the status of the process instead of using ps. If the unit file can't be found it will fallback to using ps. Moving forward we'll delete that path once everything is updated. Change-Id: I2bc2674c1c29f8970983a12d75ccb3d05fdb9103 --- inc/upgrade | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/inc/upgrade b/inc/upgrade index 04603407..8a6e3284 100644 --- a/inc/upgrade +++ b/inc/upgrade @@ -112,10 +112,16 @@ function register_project_for_upgrade { function is_service_running { local name="$1" - # the following is needed to filter out upgrade / shutdown scripts - ps auxw | grep -v grep | grep -v shutdown.sh | grep -v upgrade.sh | grep -e "${name}" - local exitcode=$? - # some times I really hate bash reverse binary logic + local exitcode=0 + if $SYSTEMCTL is-enabled "devstack@$name" --no-pager; then + $SYSTEMCTL status "devstack@$name" --no-pager + exitcode=$? + # If the unit is not found, so fallback to the ps approach + else + deprecated "Using the process name with ps for service status is deprecated, please update to use the systemd unit name" + ps auxw | grep -v grep | grep -v shutdown.sh | grep -v upgrade.sh | grep -e "${name}" + exitcode=$? + fi return $exitcode }