def _pre_install(self): if os.path.exists(self.prev_deploy_info_file) and not self.keep_addons_and_build_bases: self.logger.error( 'There is information on previous deployment (perhaps you try to install Klever second time)') sys.exit(errno.EINVAL) with open(self.args.deployment_configuration_file) as fp: self.deploy_conf = json.load(fp) self.logger.info('Create deployment directory') os.makedirs(self.args.deployment_directory, exist_ok=True) with open('/etc/default/klever', 'w') as fp: fp.write('KLEVER_SOURCE_DIRECTORY="{0}"\n'.format(os.path.realpath(self.args.source_directory))) fp.write('KLEVER_DEPLOYMENT_DIRECTORY="{0}"\n'.format(os.path.realpath(self.args.deployment_directory))) fp.write('KLEVER_DATA_DIR="{0}"\n' .format(os.path.realpath(self.args.data_directory) if self.args.data_directory else os.path.join(os.path.realpath(self.args.deployment_directory), 'build bases'))) fp.write("KLEVER_WORKERS={}\n".format(os.cpu_count() + 1)) fp.write("KLEVER_PYTHON_BIN_DIR={}\n".format(os.path.dirname(sys.executable))) fp.write("KLEVER_PYTHON={}\n".format(sys.executable)) media_user = get_media_user(self.logger) self.logger.info('Install systemd configuration files and services') execute_cmd(self.logger, 'mkdir', '-p', '/etc/conf.d') for dirpath, _, filenames in os.walk(os.path.join(os.path.dirname(__file__), os.path.pardir, 'systemd', 'conf.d')): for filename in filenames: shutil.copy(os.path.join(dirpath, filename), os.path.join('/etc/conf.d', filename)) for dirpath, _, filenames in os.walk(os.path.join(os.path.dirname(__file__), os.path.pardir, 'systemd', 'tmpfiles.d')): for filename in filenames: shutil.copy(os.path.join(dirpath, filename), os.path.join('/etc/tmpfiles.d', filename)) replace_media_user(os.path.join('/etc/tmpfiles.d', filename), media_user) for dirpath, _, filenames in os.walk(os.path.join(os.path.dirname(__file__), os.path.pardir, 'systemd', 'system')): for filename in filenames: shutil.copy(os.path.join(dirpath, filename), os.path.join('/etc/systemd/system', filename)) replace_media_user(os.path.join('/etc/systemd/system', filename), media_user) self._install_or_update_deps() prepare_env(self.logger, self.args.deployment_directory) self._pre_install_or_update() # Set environment variable JAVA to point out absolute path to java executable to be used for executing Java # programs within Klever. At the moment the same java will be used for all Java programs but that may be changed # in future. with open('/etc/default/klever', 'a+') as fp: fp.write("JAVA={}\n".format( os.path.join(os.path.realpath(self.args.deployment_directory), 'klever-addons', 'JRE', self.prev_deploy_info['Klever Addons']['JRE']['executable path'], 'java')))
def install_klever_bridge_production(logger, src_dir, deploy_dir, populate_just_production_presets=True): logger.info('Install/update production Klever Bridge') services = ('nginx', 'klever-bridge', 'klever-celery', 'klever-celerybeat') stop_services(logger, services) logger.info('Copy Klever Bridge configuration file for NGINX') copy_from = os.path.join(src_dir, 'bridge/conf/nginx') if os.path.exists('/etc/nginx/sites-enabled'): shutil.copy(copy_from, '/etc/nginx/sites-enabled/klever-bridge.conf') else: shutil.copy(copy_from, '/etc/nginx/conf.d/klever-bridge.conf') logger.info('Install/update Klever Bridge source/binary code') shutil.rmtree('/var/www/klever-bridge', ignore_errors=True) shutil.copytree(os.path.join(src_dir, 'bridge'), '/var/www/klever-bridge/bridge') shutil.copytree(os.path.join(src_dir, 'presets'), '/var/www/klever-bridge/presets') logger.info('Prepare media directory') media = '/var/www/klever-bridge/bridge/media' media_real = os.path.join(os.path.realpath(deploy_dir), 'klever-media') shutil.rmtree(media) execute_cmd(logger, 'mkdir', '-p', media_real) execute_cmd(logger, 'ln', '-s', '-T', media_real, media) with Cd('/var/www/klever-bridge/bridge'): with open('bridge/settings.py', 'w') as fp: fp.write('from bridge.{0} import *\n'.format('production')) if not populate_just_production_presets: fp.write('POPULATE_JUST_PRODUCTION_PRESETS = False\n') _install_klever_bridge(logger) logger.info('Collect static files') execute_cmd(logger, sys.executable, './manage.py', 'collectstatic', '--noinput') # Make available data from media, logs and static for its actual user. media_user = get_media_user(logger) user_group = '{}:{}'.format(media_user, media_user) execute_cmd(logger, 'chown', '-R', user_group, media_real) execute_cmd(logger, 'chown', '-R', user_group, '/var/www/klever-bridge/bridge/logs') execute_cmd(logger, 'chown', '-R', user_group, '/var/www/klever-bridge/bridge/static') start_services(logger, services)
def _pre_install(self): if self.prev_deploy_info: self.logger.error( 'There is information on previous deployment (perhaps you try to install Klever second time)') sys.exit(errno.EINVAL) with open(self.args.deployment_configuration_file) as fp: self.deploy_conf = json.load(fp) self.logger.info('Create deployment directory') os.makedirs(self.args.deployment_directory, exist_ok=True) with open('/etc/default/klever', 'w') as fp: fp.write('KLEVER_SOURCE_DIRECTORY="{0}"\n'.format(os.path.realpath(self.args.source_directory))) fp.write('KLEVER_DEPLOYMENT_DIRECTORY="{0}"\n'.format(os.path.realpath(self.args.deployment_directory))) fp.write('KLEVER_DATA_DIR="{0}"\n' .format(os.path.join(os.path.realpath(self.args.deployment_directory), 'klever', 'build bases') if len(self.deploy_conf['Klever Build Bases']) else os.path.join(os.path.realpath(self.args.source_directory), 'build bases'))) fp.write("KLEVER_WORKERS={}\n".format(os.cpu_count() + 1)) fp.write("KLEVER_PYTHON_BIN_DIR={}\n".format(os.path.dirname(sys.executable))) fp.write("KLEVER_PYTHON={}\n".format(sys.executable)) media_user = get_media_user(self.logger) self.logger.info('Install systemd configuration files and services') execute_cmd(self.logger, 'mkdir', '-p', '/etc/conf.d') for dirpath, _, filenames in os.walk(os.path.join(os.path.dirname(__file__), os.path.pardir, 'systemd', 'conf.d')): for filename in filenames: shutil.copy(os.path.join(dirpath, filename), os.path.join('/etc/conf.d', filename)) for dirpath, _, filenames in os.walk(os.path.join(os.path.dirname(__file__), os.path.pardir, 'systemd', 'tmpfiles.d')): for filename in filenames: shutil.copy(os.path.join(dirpath, filename), os.path.join('/etc/tmpfiles.d', filename)) replace_media_user(os.path.join('/etc/tmpfiles.d', filename), media_user) for dirpath, _, filenames in os.walk(os.path.join(os.path.dirname(__file__), os.path.pardir, 'systemd', 'system')): for filename in filenames: shutil.copy(os.path.join(dirpath, filename), os.path.join('/etc/systemd/system', filename)) replace_media_user(os.path.join('/etc/systemd/system', filename), media_user) self._install_or_update_deps() prepare_env(self.logger, self.args.deployment_directory) self._pre_install_or_update()