summaryrefslogtreecommitdiffstats
path: root/install/tools/ipa-ca-install
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2012-05-31 14:34:09 +0200
committerMartin Kosek <mkosek@redhat.com>2012-05-31 14:37:27 +0200
commit0ca29fac9af4cd437a8536f28ffd25923ec3f8cd (patch)
tree6804ca5316f511d83ee6898f19eea8b9ef9092ea /install/tools/ipa-ca-install
parent9e877585e213a9fccec8ff9b3dcb876b2ec65696 (diff)
downloadfreeipa-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-ca-install')
-rwxr-xr-xinstall/tools/ipa-ca-install65
1 files changed, 25 insertions, 40 deletions
diff --git a/install/tools/ipa-ca-install b/install/tools/ipa-ca-install
index 55b4dbfb8..4d7be217d 100755
--- a/install/tools/ipa-ca-install
+++ b/install/tools/ipa-ca-install
@@ -21,7 +21,7 @@
import sys
import socket
-import os, traceback, shutil
+import os, shutil
from ipapython import ipautil
from ipapython import services as ipaservices
@@ -39,8 +39,9 @@ from ipapython.config import IPAOptionParser
from ipapython import sysrestore
from ipapython.ipa_log_manager import *
-CACERT="/etc/ipa/ca.crt"
-REPLICA_INFO_TOP_DIR=None
+log_file_name = "/var/log/ipareplica-ca-install.log"
+CACERT = "/etc/ipa/ca.crt"
+REPLICA_INFO_TOP_DIR = None
def parse_options():
usage = "%prog [options] REPLICA_FILE"
@@ -72,7 +73,12 @@ def get_dirman_password():
def main():
safe_options, options, filename = parse_options()
- standard_logging_setup("/var/log/ipareplica-ca-install.log", debug=options.debug)
+
+ if os.geteuid() != 0:
+ sys.exit("\nYou must be root to run this script.\n")
+
+ standard_logging_setup(log_file_name, debug=options.debug)
+
root_logger.debug('%s was invoked with argument "%s" and options: %s' % (sys.argv[0], filename, safe_options))
if not ipautil.file_exists(filename):
@@ -150,41 +156,20 @@ def main():
# We need to restart apache as we drop a new config file in there
ipaservices.knownservices.httpd.restart(capture_output=True)
-try:
- if not os.geteuid()==0:
- sys.exit("\nYou must be root to run this script.\n")
+fail_message = '''
+Your system may be partly configured.
+Run /usr/sbin/ipa-server-install --uninstall to clean up.
+'''
- main()
- sys.exit(0)
-except SystemExit, e:
- sys.exit(e)
-except socket.error, (errno, errstr):
- print errstr
-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 ""
- print "Please fix your /etc/hosts file and restart the setup program"
-except Exception, e:
- print "creation of replica failed: %s" % str(e)
- message = str(e)
- for str in traceback.format_tb(sys.exc_info()[2]):
- message = message + "\n" + str
- root_logger.debug(message)
-except KeyboardInterrupt:
- print "Installation cancelled."
-finally:
- # always try to remove decrypted replica file
+if __name__ == '__main__':
try:
- if REPLICA_INFO_TOP_DIR:
- shutil.rmtree(REPLICA_INFO_TOP_DIR)
- except OSError:
- pass
-
-print ""
-print "Your system may be partly configured."
-print "Run /usr/sbin/ipa-server-install --uninstall to clean up."
-
-# the only way to get here is on error or ^C
-sys.exit(1)
+ installutils.run_script(main, log_file_name=log_file_name,
+ operation_name='ipa-ca-install',
+ fail_message=fail_message)
+ finally:
+ # always try to remove decrypted replica file
+ try:
+ if REPLICA_INFO_TOP_DIR:
+ shutil.rmtree(REPLICA_INFO_TOP_DIR)
+ except OSError:
+ pass