Use explicit state check for barbican-api

Replace exit code checking with explicit state comparison when
detecting if barbican-api.service is active. This handles edge
cases like "failed" or "activating" states more reliably.

Test Plan:
PASS: build-pkgs
PASS: Install ISO and bootstrap
PASS: barbican-api.service must be inactive after sm is started
PASS: Replicate the odd behavior of barbican-api.service:
      systemctl start barbican-api.service
      It was noticed that sm calls the <start> method on any change
      on PIDFile, so SM should stop barbican-api.service whenever it
      starts, since it changes the PIDFile. Check barbican-api.log
      for these messages:
      INFO: Barbican start
      INFO: OpenStack Key Management API (barbican-api) managed by
            systemd identified. Stopping it...
      Check barbican-api.service status, it should be inactive.

Story: 2011360
Task:

Change-Id: Ib5909f1533afa3694381e49b2fe2369463ccca6e
Signed-off-by: sharang bhardwaj <sharang.bhardwaj@windriver.com>
This commit is contained in:
sharang bhardwaj
2026-03-03 01:33:31 -05:00
committed by Sai Lakshmi Teja Vanka
parent e52f5f7976
commit c6e133cee1
+19 -8
View File
@@ -10,7 +10,7 @@
# Support: openstack@lists.launchpad.net
# License: Apache Software License (ASL) 2.0
#
# Copyright (c) 2018-2019,2025 Wind River Systems, Inc.
# Copyright (c) 2018-2019,2025-2026 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
@@ -239,16 +239,27 @@ barbican_api_monitor() {
barbican_api_stop_systemd_managed_instance() {
local rc
local codename=$(lsb_release -cs)
# Check if barbican-api.service initialized during bootstrap is still running
# This a workaround for https://bugs.launchpad.net/starlingx/+bug/2122366
systemctl is-active --quiet barbican-api.service
rc=$?
if [ $rc -eq 0 ]; then
ocf_log info "OpenStack Key Management API (barbican-api) managed by systemd identified. Stopping it..."
systemctl stop --quiet barbican-api.service
systemctl reset-failed --quiet barbican-api.service
systemctl disable --quiet barbican-api.service
if [ "$codename" = "bullseye" ]; then
systemctl is-active --quiet barbican-api.service
rc=$?
if [ $rc -eq 0 ]; then
ocf_log info "OpenStack Key Management API (barbican-api) managed by systemd identified. Stopping it..."
systemctl stop --quiet barbican-api.service
systemctl reset-failed --quiet barbican-api.service
systemctl disable --quiet barbican-api.service
fi
else
state=$(systemctl is-active barbican-api.service)
if [ "$state" != "inactive" ]; then
ocf_log info "OpenStack Key Management API (barbican-api) managed by systemd identified. Stopping it..."
systemctl stop --quiet barbican-api.service
systemctl reset-failed --quiet barbican-api.service
systemctl disable --quiet barbican-api.service
fi
fi
}