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-server-install | |
parent | 9e877585e213a9fccec8ff9b3dcb876b2ec65696 (diff) | |
download | freeipa.git-0ca29fac9af4cd437a8536f28ffd25923ec3f8cd.tar.gz freeipa.git-0ca29fac9af4cd437a8536f28ffd25923ec3f8cd.tar.xz freeipa.git-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-server-install')
-rwxr-xr-x | install/tools/ipa-server-install | 57 |
1 files changed, 24 insertions, 33 deletions
diff --git a/install/tools/ipa-server-install b/install/tools/ipa-server-install index e7b82364..871bfd52 100755 --- a/install/tools/ipa-server-install +++ b/install/tools/ipa-server-install @@ -34,7 +34,6 @@ import subprocess import signal import shutil import glob -import traceback import pickle import random import tempfile @@ -50,7 +49,7 @@ from ipaserver.install import certs from ipaserver.install import cainstance from ipaserver.install import memcacheinstance -from ipaserver.install import service +from ipaserver.install import service, installutils from ipapython import version from ipaserver.install.installutils import * from ipaserver.plugins.ldap2 import ldap2 @@ -1110,37 +1109,29 @@ def main(): os.remove(ANSWER_CACHE) return 0 -try: - success = True +if __name__ == '__main__': + success = False try: - 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 Exception, e: - success = False - if uninstalling: - message = "Unexpected error - see ipaserver-uninstall.log for details:\n %s" % unicode(e) + # FIXME: Common option parsing, logging setup, etc should be factored + # out from all install scripts + safe_options, options = parse_options() + if options.uninstall: + log_file_name = "/var/log/ipaserver-uninstall.log" else: - message = "Unexpected error - see ipaserver-install.log for details:\n %s" % unicode(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) -finally: - if pw_name and ipautil.file_exists(pw_name): - os.remove(pw_name) + log_file_name = "/var/log/ipaserver-install.log" - 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 + installutils.run_script(main, log_file_name=log_file_name, + operation_name='ipa-server-install') + success = True + + 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 |