How to test:

1) ipa-server-install -p secret123 -a secret123 --hostname
ipa.example.com
2) Continue in interactive wizard until IP address is requested (as
ipa.example.com cannot be resolved)
3) When it is entered and ipa-server-install gives this output:

# ipa-server-install -p kokos123 -a kokos123 --hostname ipa.example.com
--setup-dns
...
Please confirm the domain name [example.com]: 

Unable to resolve IP address for host name
Please provide the IP address to be used for this host name: 10.16.78.93
Adding [10.16.78.93 ipa.example.com] to your /etc/hosts file <<<<<
...

hit CTRL+C to quit from the installation.
4) Try running ipa-server-install again. It will fail as /etc/hosts has
been changed - this patch fixes it.
>From fb3b36c7276ff7ecee6e0754a4399e6e635b044d Mon Sep 17 00:00:00 2001
From: Martin Kosek <[email protected]>
Date: Tue, 8 Nov 2011 15:45:30 +0100
Subject: [PATCH] Make ipa-server-install clean after itself

ipa-server-install may create some files in the first phase of
installation before the actual installation and configuring of
services starts. If the installation is interrupted, these files
may prevent installing the server again until IPA server is
uninstalled. This may be confusing and annoying for the user.

This patch safely recovers all known files that could be created
in the first phase of the installation. No clean up is done if
the actual installation has not started yet or the installation
returned success.

https://fedorahosted.org/freeipa/ticket/1980
---
 install/tools/ipa-server-install |   45 ++++++++++++++++++++++++++++++-------
 1 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/install/tools/ipa-server-install b/install/tools/ipa-server-install
index 1dbeef59620ff135efd68fb47fef740015b62639..9ac4bcb6e71d29cf33aadd93f6c632bfcafea041 100755
--- a/install/tools/ipa-server-install
+++ b/install/tools/ipa-server-install
@@ -66,6 +66,7 @@ from ipapython import services as ipaservices
 
 pw_name = None
 uninstalling = False
+installation_cleanup = True
 
 VALID_SUBJECT_ATTRS = ['cn', 'st', 'o', 'ou', 'dnqualifier', 'c',
                        'serialnumber', 'l', 'title', 'sn', 'givenname',
@@ -547,6 +548,7 @@ def main():
     global ds
     global pw_name
     global uninstalling
+    global installation_cleanup
     ds = None
 
     safe_options, options = parse_options()
@@ -559,16 +561,19 @@ def main():
 
     if options.uninstall:
         uninstalling = True
+        installation_cleanup = False
         standard_logging_setup("/var/log/ipaserver-uninstall.log", options.debug)
     else:
         standard_logging_setup("/var/log/ipaserver-install.log", options.debug)
         print "\nThe log file for this installation can be found in /var/log/ipaserver-install.log"
         if not options.external_ca and not options.external_cert_file and is_ipa_configured():
+            installation_cleanup = False
             sys.exit("IPA server is already configured on this system.\n"
                      + "If you want to reinstall the IPA server please uninstall it first.")
 
         client_fstore = sysrestore.FileStore('/var/lib/ipa-client/sysrestore')
         if client_fstore.has_files():
+            installation_cleanup = False
             sys.exit("IPA client is already configured on this system.\n"
                      + "Please uninstall it first before configuring the IPA server.")
 
@@ -753,7 +758,17 @@ def main():
     domain_name = domain_name.lower()
 
     # Check we have a public IP that is associated with the hostname
-    hostaddr = resolve_host(host_name)
+    try:
+        hostaddr = resolve_host(host_name)
+    except HostnameLocalhost:
+        print >> sys.stderr, "The hostname resolves to the localhost address (127.0.0.1/::1)"
+        print >> sys.stderr, "Please change your /etc/hosts file so that the hostname"
+        print >> sys.stderr, "resolves to the ip address of your network interface."
+        print >> sys.stderr, "The KDC service does not listen on localhost"
+        print >> sys.stderr, ""
+        print >> sys.stderr, "Please fix your /etc/hosts file and restart the setup program"
+        sys.exit(1)
+
     if hostaddr is not None:
         ip = CheckedIPAddress(hostaddr, match_local=True)
     else:
@@ -858,6 +873,10 @@ def main():
         dns_forwarders = ()
     logging.debug("will use dns_forwarders: %s\n" % str(dns_forwarders))
 
+    # Installation has started. No IPA sysrestore items are restored in case of
+    # failure to enable root cause investigation
+    installation_cleanup = False
+
     # Create the management framework config file and finalize api
     target_fname = '/etc/ipa/default.conf'
     fd = open(target_fname, "w")
@@ -1136,18 +1155,18 @@ def main():
     return 0
 
 try:
+    success = True
     try:
-        sys.exit(main())
+        rval = main()
+        if rval != 0:
+            success = False
+        sys.exit(rval)
     except SystemExit, e:
+        if e.code is not None or e.code != 0:
+            success = False
         sys.exit(e)
-    except HostnameLocalhost:
-        print "The hostname resolves to the localhost address (127.0.0.1/::1)"
-        print "Please change your /etc/hosts file so that the hostname"
-        print "resolves to the ip address of your network interface."
-        print "The KDC service does not listen on localhost"
-        print ""
-        print "Please fix your /etc/hosts file and restart the setup program"
     except Exception, e:
+        success = False
         if uninstalling:
             message = "Unexpected error - see ipaserver-uninstall.log for details:\n %s" % str(e)
         else:
@@ -1161,3 +1180,11 @@ try:
 finally:
     if pw_name and ipautil.file_exists(pw_name):
         os.remove(pw_name)
+
+    if not success and installation_cleanup:
+        # Do a cautious clean up as we don't know what failed and what is
+        # the state of the environment
+        try:
+            fstore.restore_file('/etc/hosts')
+        except:
+            pass
-- 
1.7.6.4

_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to