590d18
From 92224c6e83ca7ad196478b0057b523b6f2b7d150 Mon Sep 17 00:00:00 2001
590d18
From: David Kupka <dkupka@redhat.com>
590d18
Date: Wed, 26 Aug 2015 15:10:16 +0200
590d18
Subject: [PATCH] ipactl: Do not start/stop/restart single service multiple
590d18
 times
590d18
590d18
In case multiple services are provided by single system daemon
590d18
it is not needed to start/stop/restart it mutiple time.
590d18
590d18
https://fedorahosted.org/freeipa/ticket/5248
590d18
590d18
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
590d18
---
590d18
 install/tools/ipactl | 17 ++++++++++++++++-
590d18
 1 file changed, 16 insertions(+), 1 deletion(-)
590d18
590d18
diff --git a/install/tools/ipactl b/install/tools/ipactl
590d18
index 52dfe67ddb65939bc1f431ccc67d9f03114c0454..acad7ff3771561d5dce530317b65aaf117f153a1 100755
590d18
--- a/install/tools/ipactl
590d18
+++ b/install/tools/ipactl
590d18
@@ -45,6 +45,16 @@ def check_IPA_configuration():
590d18
         raise IpactlError("IPA is not configured " +
590d18
                           "(see man pages of ipa-server-install for help)", 6)
590d18
 
590d18
+def deduplicate(lst):
590d18
+    new_lst = []
590d18
+    s = set(lst)
590d18
+    for i in lst:
590d18
+        if i in s:
590d18
+            s.remove(i)
590d18
+            new_lst.append(i)
590d18
+
590d18
+    return new_lst
590d18
+
590d18
 def is_dirsrv_debugging_enabled():
590d18
     """
590d18
     Check the 389-ds instance to see if debugging is enabled.
590d18
@@ -283,6 +293,7 @@ def ipa_start(options):
590d18
         # no service to start
590d18
         return
590d18
 
590d18
+    svc_list = deduplicate(svc_list)
590d18
     for svc in svc_list:
590d18
         svchandle = services.service(svc)
590d18
         try:
590d18
@@ -321,6 +332,7 @@ def ipa_stop(options):
590d18
             finally:
590d18
                 raise IpactlError()
590d18
 
590d18
+    svc_list = deduplicate(svc_list)
590d18
     for svc in reversed(svc_list):
590d18
         svchandle = services.service(svc)
590d18
         try:
590d18
@@ -398,6 +410,7 @@ def ipa_restart(options):
590d18
 
590d18
     if len(old_svc_list) != 0:
590d18
         # we need to definitely stop some services
590d18
+        old_svc_list = deduplicate(old_svc_list)
590d18
         for svc in reversed(old_svc_list):
590d18
             svchandle = services.service(svc)
590d18
             try:
590d18
@@ -422,7 +435,7 @@ def ipa_restart(options):
590d18
 
590d18
     if len(svc_list) != 0:
590d18
         # there are services to restart
590d18
-
590d18
+        svc_list = deduplicate(svc_list)
590d18
         for svc in svc_list:
590d18
             svchandle = services.service(svc)
590d18
             try:
590d18
@@ -444,6 +457,7 @@ def ipa_restart(options):
590d18
 
590d18
     if len(new_svc_list) != 0:
590d18
         # we still need to start some services
590d18
+        new_svc_list = deduplicate(new_svc_list)
590d18
         for svc in new_svc_list:
590d18
             svchandle = services.service(svc)
590d18
             try:
590d18
@@ -494,6 +508,7 @@ def ipa_status(options):
590d18
     if len(svc_list) == 0:
590d18
         return
590d18
 
590d18
+    svc_list = deduplicate(svc_list)
590d18
     for svc in svc_list:
590d18
         svchandle = services.service(svc)
590d18
         try:
590d18
-- 
590d18
2.4.3
590d18