From 928ab51be669d7af7a28205acb9eb7e9b46e189e Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Tue, 26 Jan 2021 10:12:31 -0500 Subject: [PATCH] ipactl: support script status 3, program is not running Return status 3 if ipactl status can't start 389-ds or if any of the expected services is not running. https://pagure.io/freeipa/issue/8588 Signed-off-by: Rob Crittenden Reviewed-By: Florence Blanc-Renaud --- ipaserver/install/ipactl.py | 41 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/ipaserver/install/ipactl.py b/ipaserver/install/ipactl.py index f813d0d72..545a4843e 100644 --- a/ipaserver/install/ipactl.py +++ b/ipaserver/install/ipactl.py @@ -613,6 +613,22 @@ def ipa_restart(options): def ipa_status(options): + """Report status of IPA-owned processes + + The LSB defines the possible status values as: + + 0 program is running or service is OK + 1 program is dead and /var/run pid file exists + 2 program is dead and /var/lock lock file exists + 3 program is not running + 4 program or service status is unknown + 5-99 reserved for future LSB use + 100-149 reserved for distribution use + 150-199 reserved for application use + 200-254 reserved + + We only really care about 0, 3 and 4. + """ try: dirsrv = services.knownservices.dirsrv @@ -627,7 +643,8 @@ def ipa_status(options): svc_list = [] except Exception as e: raise IpactlError( - "Failed to get list of services to probe status: " + str(e) + "Failed to get list of services to probe status: " + str(e), + 4 ) dirsrv = services.knownservices.dirsrv @@ -636,19 +653,19 @@ def ipa_status(options): print("Directory Service: RUNNING") else: print("Directory Service: STOPPED") - if len(svc_list) == 0: - print( - ( - "Directory Service must be running in order to " - "obtain status of other services" - ) - ) except Exception as e: - raise IpactlError("Failed to get Directory Service status") + raise IpactlError("Failed to get Directory Service status", 4) if len(svc_list) == 0: - return + raise IpactlError( + ( + "Directory Service must be running in order to " + "obtain status of other services" + ), + 3, + ) + stopped = 0 for svc in svc_list: svchandle = services.service(svc, api=api) try: @@ -656,9 +673,13 @@ def ipa_status(options): print("%s Service: RUNNING" % svc) else: print("%s Service: STOPPED" % svc) + stopped += 1 except Exception: emit_err("Failed to get %s Service status" % svc) + if stopped > 0: + raise IpactlError("%d service(s) are not running" % stopped, 3) + def main(): if not os.getegid() == 0: