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
This commit is contained in:
Matthew Treinish 2017-08-30 10:21:27 -04:00
parent 82b783f77c
commit 0965bc0dce
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
1 changed files with 10 additions and 4 deletions

View File

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