2015-04-02 07:14:15 -05:00
|
|
|
#
|
|
|
|
# Copyright (C) 2015 FreeIPA Contributors see COPYING for license
|
|
|
|
#
|
|
|
|
|
2018-04-05 02:21:16 -05:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2017-05-23 11:35:57 -05:00
|
|
|
import logging
|
|
|
|
|
2015-04-02 07:14:15 -05:00
|
|
|
from ipalib import api
|
|
|
|
from ipaplatform.paths import paths
|
2015-05-28 06:39:37 -05:00
|
|
|
from ipapython import admintool
|
2015-04-02 07:14:15 -05:00
|
|
|
from ipaserver.install import installutils
|
2015-05-28 06:39:37 -05:00
|
|
|
from ipaserver.install import server
|
2015-04-02 07:14:15 -05:00
|
|
|
|
2017-05-23 11:35:57 -05:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2015-04-02 07:14:15 -05:00
|
|
|
|
|
|
|
class ServerUpgrade(admintool.AdminTool):
|
|
|
|
log_file_name = paths.IPAUPGRADE_LOG
|
|
|
|
command_name = 'ipa-server-upgrade'
|
|
|
|
|
|
|
|
usage = "%prog [options]"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def add_options(cls, parser):
|
2015-04-10 08:42:58 -05:00
|
|
|
super(ServerUpgrade, cls).add_options(parser)
|
|
|
|
parser.add_option("--force", action="store_true",
|
|
|
|
dest="force", default=False,
|
|
|
|
help="force upgrade (alias for --skip-version-check)")
|
|
|
|
parser.add_option("--skip-version-check", action="store_true",
|
|
|
|
dest="skip_version_check", default=False,
|
|
|
|
help="skip version check. WARNING: this may break "
|
|
|
|
"your system")
|
2015-04-02 07:14:15 -05:00
|
|
|
|
|
|
|
def validate_options(self):
|
|
|
|
super(ServerUpgrade, self).validate_options(needs_root=True)
|
|
|
|
|
2018-08-22 11:29:07 -05:00
|
|
|
installutils.check_server_configuration()
|
|
|
|
|
2015-04-10 08:42:58 -05:00
|
|
|
if self.options.force:
|
|
|
|
self.options.skip_version_check = True
|
|
|
|
|
2015-04-02 07:14:15 -05:00
|
|
|
def setup_logging(self):
|
|
|
|
super(ServerUpgrade, self).setup_logging(log_file_mode='a')
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
super(ServerUpgrade, self).run()
|
|
|
|
|
2016-11-28 09:24:33 -06:00
|
|
|
api.bootstrap(in_server=True, context='updates', confdir=paths.ETC_IPA)
|
2015-04-02 07:14:15 -05:00
|
|
|
api.finalize()
|
|
|
|
|
2015-05-12 06:31:57 -05:00
|
|
|
try:
|
2015-05-28 06:39:37 -05:00
|
|
|
server.upgrade_check(self.options)
|
|
|
|
server.upgrade()
|
|
|
|
except RuntimeError as e:
|
|
|
|
raise admintool.ScriptError(str(e))
|
2015-04-02 07:14:15 -05:00
|
|
|
|
|
|
|
def handle_error(self, exception):
|
2015-07-08 05:19:58 -05:00
|
|
|
if not isinstance(exception, SystemExit):
|
|
|
|
# do not log this message when ipa is not installed
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.error("IPA server upgrade failed: Inspect "
|
|
|
|
"/var/log/ipaupgrade.log and run command "
|
|
|
|
"ipa-server-upgrade manually.")
|
2015-04-02 07:14:15 -05:00
|
|
|
return installutils.handle_error(exception, self.log_file_name)
|