diff options
author | Petr Viktorin <pviktori@redhat.com> | 2012-05-31 14:34:09 +0200 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2012-05-31 14:37:27 +0200 |
commit | 0ca29fac9af4cd437a8536f28ffd25923ec3f8cd (patch) | |
tree | 6804ca5316f511d83ee6898f19eea8b9ef9092ea /install/tools/ipa-dns-install | |
parent | 9e877585e213a9fccec8ff9b3dcb876b2ec65696 (diff) | |
download | freeipa-0ca29fac9af4cd437a8536f28ffd25923ec3f8cd.tar.gz freeipa-0ca29fac9af4cd437a8536f28ffd25923ec3f8cd.tar.xz freeipa-0ca29fac9af4cd437a8536f28ffd25923ec3f8cd.zip |
Move install script error handling to a common function
All of our install/admin scripts had a try/except block calling the
main function and handling common exceptions. These were copy-pasted
from each other and modified to various levels of sophistication.
This refactors them out of installers to a single function, which
includes a final pass/fail message for all of the scripts.
Non-install scripts that set up the same log handler levels for
stderr and log file are not changed, as it's not possible to log
to only the logfile without changing the logger configuration.
https://fedorahosted.org/freeipa/ticket/2071
Diffstat (limited to 'install/tools/ipa-dns-install')
-rwxr-xr-x | install/tools/ipa-dns-install | 34 |
1 files changed, 7 insertions, 27 deletions
diff --git a/install/tools/ipa-dns-install b/install/tools/ipa-dns-install index 10547c342..063cf5bf5 100755 --- a/install/tools/ipa-dns-install +++ b/install/tools/ipa-dns-install @@ -19,8 +19,6 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # -import traceback - from ipaserver.plugins.ldap2 import ldap2 from ipaserver.install import service, bindinstance, ntpinstance, httpinstance from ipaserver.install.installutils import * @@ -34,6 +32,8 @@ import krbV import ldap from ipapython.ipa_log_manager import * +log_file_name = "/var/log/ipaserver-install.log" + def parse_options(): parser = IPAOptionParser(version=version.VERSION) parser.add_option("-p", "--ds-password", dest="dm_password", @@ -89,8 +89,8 @@ def main(): if os.getegid() != 0: sys.exit("Must be root to setup server") - standard_logging_setup("/var/log/ipaserver-install.log", debug=options.debug, filemode='a') - print "\nThe log file for this installation can be found in /var/log/ipaserver-install.log" + standard_logging_setup(log_file_name, debug=options.debug, filemode='a') + print "\nThe log file for this installation can be found in %s" % log_file_name root_logger.debug('%s was invoked with options: %s' % (sys.argv[0], safe_options)) root_logger.debug("missing options might be asked for interactively later\n") @@ -243,26 +243,6 @@ def main(): return 0 -try: - sys.exit(main()) -except SystemExit, e: - sys.exit(e) -except KeyboardInterrupt: - print "Installation cancelled." -except RuntimeError, e: - print str(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: - message = "Unexpected error - see ipaserver-install.log for details:\n %s" % str(e) - print message - message = str(e) - for str in traceback.format_tb(sys.exc_info()[2]): - message = message + "\n" + str - root_logger.debug(message) - sys.exit(1) +if __name__ == '__main__': + installutils.run_script(main, log_file_name=log_file_name, + operation_name='ipa-dns-install') |