Hi,
I reviewed this old patch:

If an error occurs in the start up sequence in ipactl start/restart,            
all the services are stopped. Using the --force/-f option prevents              
   
stopping of services that have successfully started.                            
                                                                                
https://fedorahosted.org/freeipa/ticket/3509   

Seems like fine to me.
Thanks
Adam
From 1893484613cde5c1e3b89cf3b1114ea5561d8f32 Mon Sep 17 00:00:00 2001
From: Ana Krivokapic <akriv...@redhat.com>
Date: Wed, 13 Mar 2013 11:50:24 -0400
Subject: [PATCH] Add --force option to ipactl

If an error occurs in the start up sequence in ipactl start/restart,
all the services are stopped. Using the --force option prevents
stopping of services that have successfully started.

https://fedorahosted.org/freeipa/ticket/3509
---
 install/tools/ipactl       | 87 +++++++++++++++++++++++-----------------------
 install/tools/man/ipactl.8 |  6 ++++
 2 files changed, 49 insertions(+), 44 deletions(-)

diff --git a/install/tools/ipactl b/install/tools/ipactl
index 3f5417464e62ec29e478d0dce981ca55a413b6ba..6d58d1f2fd7b3b6e5eccd07033805edba3d5074a 100755
--- a/install/tools/ipactl
+++ b/install/tools/ipactl
@@ -87,6 +87,8 @@ def parse_options():
 
     parser.add_option("-d", "--debug", action="store_true", dest="debug",
                       help="Display debugging information")
+    parser.add_option("-f", "--force", action="store_true", dest="force",
+                      help="If ipactl action fails, do not stop the services that are already running")
 
     options, args = parser.parse_args()
     safe_options = parser.get_safe_opts(options)
@@ -189,6 +191,23 @@ def get_config_from_file():
 
     return ordered_list
 
+
+def stop_services(svc_list):
+    for svc in svc_list:
+        svc_off = ipaservices.service(svc)
+        try:
+            svc_off.stop(capture_output=False)
+        except:
+            pass
+
+
+def stop_dirsrv(dirsrv):
+    try:
+        dirsrv.stop(capture_output=False)
+    except:
+        pass
+
+
 def ipa_start(options):
 
     if os.path.isfile(ipaservices.get_svc_list_file()):
@@ -214,10 +233,10 @@ def ipa_start(options):
     except Exception, e:
         emit_err("Failed to data from service file: " + str(e))
         emit_err("Shutting down")
-        try:
-            dirsrv.stop(capture_output=False)
-        except:
-            pass
+
+        if not options.force:
+            stop_dirsrv(dirsrv)
+
         if isinstance(e, IpactlError):
             # do not display any other error message
             raise IpactlError(rval=e.rval)
@@ -236,16 +255,11 @@ def ipa_start(options):
         except:
             emit_err("Failed to start %s Service" % svc)
             emit_err("Shutting down")
-            for svc in svc_list:
-                svc_off = ipaservices.service(svc)
-                try:
-                    svc_off.stop(capture_output=False)
-                except:
-                    pass
-            try:
-                dirsrv.stop(capture_output=False)
-            except:
-                pass
+
+            if not options.force:
+                stop_services(svc_list)
+                stop_dirsrv(dirsrv)
+
             raise IpactlError("Aborting ipactl")
 
 def ipa_stop(options):
@@ -354,16 +368,11 @@ def ipa_restart(options):
     except Exception, e:
         emit_err("Failed to restart Directory Service: " + str(e))
         emit_err("Shutting down")
-        for svc in reversed(svc_list):
-            svc_off = ipaservices.service(svc)
-            try:
-                svc_off.stop(capture_output=False)
-            except:
-                pass
-        try:
-            dirsrv.stop(capture_output=False)
-        except:
-            pass
+
+        if not options.force:
+            stop_services(reversed(svc_list))
+            stop_dirsrv(dirsrv)
+
         raise IpactlError("Aborting ipactl")
 
     if len(svc_list) != 0:
@@ -377,16 +386,11 @@ def ipa_restart(options):
             except:
                 emit_err("Failed to restart %s Service" % svc)
                 emit_err("Shutting down")
-                for svc in reversed(svc_list):
-                    svc_off = ipaservices.service(svc)
-                    try:
-                        svc_off.stop(capture_output=False)
-                    except:
-                        pass
-                try:
-                    dirsrv.stop(capture_output=False)
-                except:
-                    pass
+
+                if not options.force:
+                    stop_services(reversed(svc_list))
+                    stop_dirsrv(dirsrv)
+
                 raise IpactlError("Aborting ipactl")
 
     if len(new_svc_list) != 0:
@@ -399,16 +403,11 @@ def ipa_restart(options):
             except:
                 emit_err("Failed to start %s Service" % svc)
                 emit_err("Shutting down")
-                for svc in reversed(svc_list):
-                    svc_off = ipaservices.service(svc)
-                    try:
-                        svc_off.stop(capture_output=False)
-                    except:
-                        pass
-                try:
-                    dirsrv.stop(capture_output=False)
-                except:
-                    pass
+
+                if not options.force:
+                    stop_services(reversed(svc_list))
+                    stop_dirsrv(dirsrv)
+
                 raise IpactlError("Aborting ipactl")
 
 def ipa_status(options):
diff --git a/install/tools/man/ipactl.8 b/install/tools/man/ipactl.8
index 05be8e0e29f792ad2a2159ca3f8f38624a42ffa4..e80c5eb6d9e783b01b41788345dfce6a9f34f71a 100644
--- a/install/tools/man/ipactl.8
+++ b/install/tools/man/ipactl.8
@@ -37,3 +37,9 @@ Stop all of the services that make up IPA
 .TP 
 restart
 Stop then start all of the services that make up IPA
+.TP
+\fB\-d\fR, \fB\-\-debug\fR
+Display debugging information
+.TP
+\fB\-f\fR, \fB\-\-force\fR
+If ipactl action fails, do not stop the services that are already running
-- 
1.8.5.3

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to