Exemplo n.º 1
0
    def get_elasticsearch_install_location(self, package_name):
        """
        Get the path to the Elasticsearch install

        """

        url = get_elasticsearch_download_url(os.path.join(settings.ROOT_DIR, 'install'))
        file_name = url.split('/')[-1]
        file_name_wo_extention = file_name[:-4]
        package_root = settings.PACKAGE_ROOT
        return os.path.join(package_root, 'elasticsearch', file_name_wo_extention)
Exemplo n.º 2
0
    def get_elasticsearch_install_location(self, package_name):
        """
        Get the path to the Elasticsearch install

        """

        url = get_elasticsearch_download_url(os.path.join(settings.ROOT_DIR, 'install'))
        file_name = url.split('/')[-1]
        file_name_wo_extention = file_name[:-4]
        package_root = settings.PACKAGE_ROOT
        return os.path.join(package_root, 'elasticsearch', file_name_wo_extention)
Exemplo n.º 3
0
    def setup_elasticsearch(self, package_name, port=9200):
        """
        Installs Elasticsearch into the package directory and
        adds default settings for running in a test environment

        Change these settings in production

        """
        tmp_dir = settings.TMP_DIR
        install_location = self.get_elasticsearch_install_location(
            package_name)
        url = get_elasticsearch_download_url(
            os.path.join(settings.ROOT_DIR, 'install'))
        file_name = url.split('/')[-1]

        download_elasticsearch(tmp_dir)
        unzip_file(os.path.join(tmp_dir, file_name), tmp_dir)

        # Move to folder without version in name, so we can easilly find it back
        file_name_wo_extention = file_name[:-4]
        unzip_location = os.path.join(tmp_dir, file_name_wo_extention)
        os.rename(unzip_location, install_location)

        es_config_directory = os.path.join(install_location, 'config')
        try:
            os.rename(
                os.path.join(es_config_directory, 'elasticsearch.yml'),
                os.path.join(es_config_directory, 'elasticsearch.yml.orig'))
        except:
            pass

        with open(os.path.join(es_config_directory, 'elasticsearch.yml'),
                  'w') as f:
            f.write('# ----------------- FOR TESTING ONLY -----------------')
            f.write('\n# - THESE SETTINGS SHOULD BE REVIEWED FOR PRODUCTION -')
            f.write('\nnode.max_local_storage_nodes: 1')
            f.write('\nindex.number_of_shards: 1')
            f.write('\nindex.number_of_replicas: 0')
            f.write('\nhttp.port: %s' % port)
            f.write('\ndiscovery.zen.ping.multicast.enabled: false')
            f.write('\ndiscovery.zen.ping.unicast.hosts: ["localhost"]')
            f.write(
                '\ncluster.routing.allocation.disk.threshold_enabled: false')

        # install plugin
        if sys.platform == 'win32':
            os.system("call %s --install mobz/elasticsearch-head" %
                      (os.path.join(install_location, 'bin', 'plugin.bat')))
        else:
            os.chdir(os.path.join(install_location, 'bin'))
            os.system("chmod u+x plugin")
            os.system("./plugin -install mobz/elasticsearch-head")
            os.system("chmod u+x elasticsearch")
Exemplo n.º 4
0
    def install(self, install_location=None, port=None):
        """
        Installs Elasticsearch into the package directory and
        adds default settings for running in a test environment

        Change these settings in production

        """

        install_location = os.path.abspath(install_location)
        utils.ensure_dir(install_location)

        url = get_elasticsearch_download_url(os.path.join(settings.ROOT_DIR, 'install'))
        file_name = url.split('/')[-1]
        os_name = platform.system().lower()
        file_name_wo_extention = file_name.split('-%s' % os_name)[0]

        download_elasticsearch(os.path.join(settings.ROOT_DIR, 'install'))
        unzip_file(os.path.join(settings.ROOT_DIR, 'install', file_name), install_location)

        es_config_directory = os.path.join(install_location, file_name_wo_extention, 'config')
        try:
            os.rename(os.path.join(es_config_directory, 'elasticsearch.yml'), os.path.join(es_config_directory, 'elasticsearch.yml.orig'))
        except:
            pass

        os.chmod(os.path.join(install_location, file_name_wo_extention, 'bin', 'elasticsearch'), 0o755)

        def change_permissions_recursive(path, mode):
            for root, dirs, files in os.walk(path, topdown=True):
                for dir in [os.path.join(root,d) for d in dirs]:
                    os.chmod(dir, mode)
                for file in [os.path.join(root, f) for f in files]:
                    if '/bin/' in file:
                        os.chmod(file, mode)

        change_permissions_recursive(os.path.join(install_location, file_name_wo_extention, 'modules', 'x-pack-ml', 'platform'), 0o755)

        with open(os.path.join(es_config_directory, 'elasticsearch.yml'), 'w') as f:
            f.write('# ----------------- FOR TESTING ONLY -----------------')
            f.write('\n# - THESE SETTINGS SHOULD BE REVIEWED FOR PRODUCTION -')
            f.write('\n# -https://www.elastic.co/guide/en/elasticsearch/reference/6.7/important-settings.html - ')
            f.write('\nhttp.port: %s' % port)
            f.write('\n\n# for the elasticsearch-head plugin')
            f.write('\nhttp.cors.enabled: true')
            f.write('\nhttp.cors.allow-origin: "*"')
            f.write('\n')

        print('Elasticsearch installed at %s' % os.path.join(install_location, file_name_wo_extention))
Exemplo n.º 5
0
    def setup_elasticsearch(self, package_name, port=9200):
        """
        Installs Elasticsearch into the package directory and
        adds default settings for running in a test environment

        Change these settings in production

        """

        install_location = self.get_elasticsearch_install_location(package_name)
        install_root = os.path.abspath(os.path.join(install_location, ".."))
        url = get_elasticsearch_download_url(os.path.join(settings.ROOT_DIR, "install"))
        file_name = url.split("/")[-1]

        try:
            unzip_file(os.path.join(settings.ROOT_DIR, "install", file_name), install_root)
        except:
            download_elasticsearch(os.path.join(settings.ROOT_DIR, "install"))

        es_config_directory = os.path.join(install_location, "config")
        try:
            os.rename(
                os.path.join(es_config_directory, "elasticsearch.yml"),
                os.path.join(es_config_directory, "elasticsearch.yml.orig"),
            )
        except:
            pass

        with open(os.path.join(es_config_directory, "elasticsearch.yml"), "w") as f:
            f.write("# ----------------- FOR TESTING ONLY -----------------")
            f.write("\n# - THESE SETTINGS SHOULD BE REVIEWED FOR PRODUCTION -")
            f.write("\nnode.max_local_storage_nodes: 1")
            f.write("\nindex.number_of_shards: 1")
            f.write("\nindex.number_of_replicas: 0")
            f.write("\nhttp.port: %s" % port)
            f.write("\ndiscovery.zen.ping.multicast.enabled: false")
            f.write('\ndiscovery.zen.ping.unicast.hosts: ["localhost"]')
            f.write("\ncluster.routing.allocation.disk.threshold_enabled: false")

        # install plugin
        if sys.platform == "win32":
            os.system(
                "call %s --install mobz/elasticsearch-head" % (os.path.join(install_location, "bin", "plugin.bat"))
            )
        else:
            os.chdir(os.path.join(install_location, "bin"))
            os.system("chmod u+x plugin")
            os.system("./plugin -install mobz/elasticsearch-head")
            os.system("chmod u+x elasticsearch")
Exemplo n.º 6
0
    def install(self, install_location=None, port=None):
        """
        Installs Elasticsearch into the package directory and
        adds default settings for running in a test environment

        Change these settings in production

        """

        install_location = os.path.abspath(install_location)
        utils.ensure_dir(install_location)

        url = get_elasticsearch_download_url(os.path.join(settings.ROOT_DIR, 'install'))
        file_name = url.split('/')[-1]
        file_name_wo_extention, extention = os.path.splitext(file_name)

        download_elasticsearch(os.path.join(settings.ROOT_DIR, 'install'))
        unzip_file(os.path.join(settings.ROOT_DIR, 'install', file_name), install_location)

        es_config_directory = os.path.join(install_location, file_name_wo_extention, 'config')
        try:
            os.rename(os.path.join(es_config_directory, 'elasticsearch.yml'), os.path.join(es_config_directory, 'elasticsearch.yml.orig'))
        except: pass

        os.chmod(os.path.join(install_location, file_name_wo_extention, 'bin', 'elasticsearch'), 0755)

        with open(os.path.join(es_config_directory, 'elasticsearch.yml'), 'w') as f:
            f.write('# ----------------- FOR TESTING ONLY -----------------')
            f.write('\n# - THESE SETTINGS SHOULD BE REVIEWED FOR PRODUCTION -')
            f.write('\n# -https://www.elastic.co/guide/en/elasticsearch/reference/5.0/system-config.html - ')
            f.write('\nhttp.port: %s' % port)
            f.write('\nscript.inline: true')
            f.write('\n\n# for the elasticsearch-head plugin')
            f.write('\nhttp.cors.enabled: true')
            f.write('\nhttp.cors.allow-origin: "*"')
            f.write('\n')

        print 'Elasticsearch installed at %s' % os.path.join(install_location, file_name_wo_extention)