install
Installation Manager for Logstash and its dependencies.
To import...
from dynamite_nsm.services.logstash import install as logstash_install
InstallManager
__init__(self, configuration_directory, install_directory, log_directory, download_logstash_archive=True, stdout=False, verbose=False)
special
Install Logstash
Parameters:
Name | Type | Description | Default |
---|---|---|---|
configuration_directory |
str |
Path to the configuration directory (E.G /etc/dynamite/logstash/) |
required |
install_directory |
str |
Path to the install directory (E.G /opt/dynamite/logstash/) |
required |
log_directory |
str |
Path to the log directory (E.G /var/log/dynamite/logstash/) |
required |
download_logstash_archive |
Optional[bool] |
If True, download the Logstash archive from a mirror |
True |
stdout |
Optional[bool] |
Print output to console |
False |
verbose |
Optional[bool] |
Include detailed debug messages |
False |
Returns:
Type | Description |
---|---|
|
None |
Source code in dynamite_nsm/services/logstash/install.py
def __init__(self, configuration_directory: str, install_directory: str, log_directory: str,
download_logstash_archive: Optional[bool] = True, stdout: Optional[bool] = False,
verbose: Optional[bool] = False):
"""Install Logstash
Args:
configuration_directory: Path to the configuration directory (E.G /etc/dynamite/logstash/)
install_directory: Path to the install directory (E.G /opt/dynamite/logstash/)
log_directory: Path to the log directory (E.G /var/log/dynamite/logstash/)
download_logstash_archive: If True, download the Logstash archive from a mirror
stdout: Print output to console
verbose: Include detailed debug messages
Returns:
None
"""
self.configuration_directory = configuration_directory
self.install_directory = install_directory
self.log_directory = log_directory
self.stdout = stdout
self.verbose = verbose
super().__init__('logstash.process', stdout=self.stdout, verbose=self.verbose)
java_home = self.dynamite_environ.get('JAVA_HOME')
if not java_home:
self.logger.info('Installing compatible version of Java.')
from dynamite_nsm.services.java import install as java_install
java_install.InstallManager(const.JVM_ROOT, stdout=stdout, verbose=verbose).setup()
if download_logstash_archive:
self.logger.info("Attempting to download Logstash (OSS) archive.")
_, archive_name, self.local_mirror_root = self.download_from_mirror(const.LOGSTASH_MIRRORS)
self.logger.info(f'Attempting to extract Logstash archive ({archive_name}).')
self.extract_archive(os.path.join(const.INSTALL_CACHE, archive_name))
self.logger.info("Extraction completed.")
else:
_, _, self.local_mirror_root = self.get_mirror_info(const.LOGSTASH_MIRRORS)
copy_logstash_fills_and_directories(self)
Copy the required Logstash files from the install cache to their respective directories
Source code in dynamite_nsm/services/logstash/install.py
def copy_logstash_fills_and_directories(self) -> None:
"""
Copy the required Logstash files from the install cache to their respective directories
"""
logstash_tarball_extracted = f'{const.INSTALL_CACHE}/{self.local_mirror_root}'
config_paths = [
'config/logstash.yml',
'config/pipelines.yml',
'config/jvm.options',
'config/log4j2.properties'
]
install_paths = [
'Gemfile',
'Gemfile.lock',
'bin/',
'data/',
'lib/',
'logstash-core/',
'logstash-core-plugin-api/',
'modules/',
'tools/',
'vendor/',
]
for conf in config_paths:
self.copy_file_or_directory_to_destination(f'{logstash_tarball_extracted}/{conf}',
self.configuration_directory)
for inst in install_paths:
self.copy_file_or_directory_to_destination(f'{logstash_tarball_extracted}/{inst}',
self.install_directory)
create_update_logstash_environment_variables(self)
Creates all the required Logstash environmental variables
Source code in dynamite_nsm/services/logstash/install.py
def create_update_logstash_environment_variables(self) -> None:
"""
Creates all the required Logstash environmental variables
"""
self.create_update_env_variable('LS_PATH_CONF', self.configuration_directory)
self.create_update_env_variable('LS_HOME', self.install_directory)
self.create_update_env_variable('LS_LOGS', self.log_directory)
UninstallManager
Uninstall Logstash
__init__(self, purge_config=True, stdout=False, verbose=False)
special
:param purge_config: If enabled, remove all the configuration files associated with this installation :param stdout: Print output to console :param verbose: Include detailed debug messages
Source code in dynamite_nsm/services/logstash/install.py
def __init__(self, purge_config: Optional[bool] = True, stdout: Optional[bool] = False,
verbose: Optional[bool] = False):
"""
:param purge_config: If enabled, remove all the configuration files associated with this installation
:param stdout: Print output to console
:param verbose: Include detailed debug messages
"""
from dynamite_nsm.services.logstash.config import ConfigManager
from dynamite_nsm.services.logstash.process import ProcessManager
env_vars = utilities.get_environment_file_dict()
ls_config = ConfigManager(configuration_directory=env_vars.get('LS_PATH_CONF'))
ls_directories = [env_vars.get('LS_HOME'), ls_config.path_logs]
if purge_config:
ls_directories.append(env_vars.get('LS_PATH_CONF'))
super().__init__('logstash.process', directories=ls_directories,
process=ProcessManager(stdout=stdout, verbose=verbose), sysctl_service_name='logstash.service',
environ_vars=['LS_HOME', 'LS_PATH_CONF'],
stdout=stdout, verbose=verbose)