Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wazuh install assistant with error handler #1760

Open
wants to merge 2 commits into
base: 4.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions unattended_installer/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ function buildInstaller() {
## JAVA_HOME
echo "export JAVA_HOME=\"/usr/share/wazuh-indexer/jdk/\"" >> "${output_script_path}"

echo "set -o pipefail" >> "${output_script_path}"
echo "shopt -s expand_aliases" >> "${output_script_path}"

echo "alias try=\"(set -e;\"" >> "${output_script_path}"
echo "alias catch=\" ); Error \\\$? || \"" >> "${output_script_path}"

## Functions for all install function modules
install_modules=($(find "${resources_installer}" -type f))
install_modules_names=($(eval "echo \"${install_modules[*]}\" | sed 's,${resources_installer}/,,g'"))
Expand Down
16 changes: 8 additions & 8 deletions unattended_installer/common_functions/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,39 +68,39 @@ function common_checkInstalled() {
dashboard_installed=""

if [ "${sys_type}" == "yum" ]; then
wazuh_installed=$(yum list installed 2>/dev/null | grep wazuh-manager)
wazuh_installed=$(yum list installed 2>/dev/null | grep wazuh-manager || true)
elif [ "${sys_type}" == "apt-get" ]; then
wazuh_installed=$(apt list --installed 2>/dev/null | grep wazuh-manager)
wazuh_installed=$(apt list --installed 2>/dev/null | grep wazuh-manager || true)
fi

if [ -d "/var/ossec" ]; then
wazuh_remaining_files=1
fi

if [ "${sys_type}" == "yum" ]; then
indexer_installed=$(yum list installed 2>/dev/null | grep wazuh-indexer)
indexer_installed=$(yum list installed 2>/dev/null | grep wazuh-indexer || true)
elif [ "${sys_type}" == "apt-get" ]; then
indexer_installed=$(apt list --installed 2>/dev/null | grep wazuh-indexer)
indexer_installed=$(apt list --installed 2>/dev/null | grep wazuh-indexer || true)
fi

if [ -d "/var/lib/wazuh-indexer/" ] || [ -d "/usr/share/wazuh-indexer" ] || [ -d "/etc/wazuh-indexer" ] || [ -f "${base_path}/search-guard-tlstool*" ]; then
indexer_remaining_files=1
fi

if [ "${sys_type}" == "yum" ]; then
filebeat_installed=$(yum list installed 2>/dev/null | grep filebeat)
filebeat_installed=$(yum list installed 2>/dev/null | grep filebeat || true)
elif [ "${sys_type}" == "apt-get" ]; then
filebeat_installed=$(apt list --installed 2>/dev/null | grep filebeat)
filebeat_installed=$(apt list --installed 2>/dev/null | grep filebeat || true)
fi

if [ -d "/var/lib/filebeat/" ] || [ -d "/usr/share/filebeat" ] || [ -d "/etc/filebeat" ]; then
filebeat_remaining_files=1
fi

if [ "${sys_type}" == "yum" ]; then
dashboard_installed=$(yum list installed 2>/dev/null | grep wazuh-dashboard)
dashboard_installed=$(yum list installed 2>/dev/null | grep wazuh-dashboard || true)
elif [ "${sys_type}" == "apt-get" ]; then
dashboard_installed=$(apt list --installed 2>/dev/null | grep wazuh-dashboard)
dashboard_installed=$(apt list --installed 2>/dev/null | grep wazuh-dashboard || true)
fi

if [ -d "/var/lib/wazuh-dashboard/" ] || [ -d "/usr/share/wazuh-dashboard" ] || [ -d "/etc/wazuh-dashboard" ] || [ -d "/run/wazuh-dashboard/" ]; then
Expand Down
15 changes: 15 additions & 0 deletions unattended_installer/install_functions/error.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Wazuh installer - dashboard.sh functions.
# Copyright (C) 2015, Wazuh Inc.
#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.

function Error() {
local retVal=$1
if [[ $retVal -gt 0 ]]
then
return 1
fi
}
103 changes: 66 additions & 37 deletions unattended_installer/install_functions/installMain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,17 @@ function main() {
# -------------- Wazuh indexer case -------------------------------

if [ -n "${indexer}" ]; then
common_logger "--- Wazuh indexer ---"
indexer_install
indexer_configure
installCommon_startService "wazuh-indexer"
indexer_initialize
try {
common_logger "--- Wazuh indexer ---"
indexer_install
indexer_configure
installCommon_startService "wazuh-indexer"
indexer_initialize
} catch {
common_logger "Wazuh-indexer installation failed"
indexer_installed="true"
installCommon_rollBack
}
fi

# -------------- Start Wazuh indexer cluster case ------------------
Expand All @@ -273,51 +279,74 @@ function main() {
if [ -n "${dashboard}" ]; then
common_logger "--- Wazuh dashboard ----"

dashboard_install
dashboard_configure
installCommon_startService "wazuh-dashboard"
installCommon_changePasswords
dashboard_initialize
try {
dashboard_install
dashboard_configure
installCommon_startService "wazuh-dashboard"
installCommon_changePasswords
dashboard_initialize
} catch {
common_logger "Wazuh-dashboard installation failed"
dashboard_installed="true"
installCommon_rollBack
}

fi

# -------------- Wazuh case ---------------------------------------

if [ -n "${wazuh}" ]; then
common_logger "--- Wazuh server ---"

manager_install
if [ -n "${server_node_types[*]}" ]; then
manager_startCluster
fi
installCommon_startService "wazuh-manager"
filebeat_install
filebeat_configure
installCommon_changePasswords
installCommon_startService "filebeat"
try {
manager_install
if [ -n "${server_node_types[*]}" ]; then
manager_startCluster
fi
installCommon_startService "wazuh-manager"
} catch {
common_logger "Wazuh-manager installation failed"
wazuh_installed="true"
installCommon_rollBack
}

try {
filebeat_install
filebeat_configure
installCommon_changePasswords
installCommon_startService "filebeat"
} catch {
common_logger "Filebeat installation failed"
filebeat_installed="true"
installCommon_rollBack
}
fi

# -------------- AIO case ------------------------------------------

if [ -n "${AIO}" ]; then

common_logger "--- Wazuh indexer ---"
indexer_install
indexer_configure
installCommon_startService "wazuh-indexer"
indexer_initialize
common_logger "--- Wazuh server ---"
manager_install
installCommon_startService "wazuh-manager"
filebeat_install
filebeat_configure
installCommon_startService "filebeat"
common_logger "--- Wazuh dashboard ---"
dashboard_install
dashboard_configure
installCommon_startService "wazuh-dashboard"
installCommon_changePasswords
dashboard_initializeAIO
try {
common_logger "--- Wazuh indexer ---"
indexer_install
indexer_configure
installCommon_startService "wazuh-indexer"
indexer_initialize
common_logger "--- Wazuh server ---"
manager_install
installCommon_startService "wazuh-manager"
filebeat_install
filebeat_configure
installCommon_startService "filebeat"
common_logger "--- Wazuh dashboard ---"
dashboard_install
dashboard_configure
installCommon_startService "wazuh-dashboard"
installCommon_changePasswords
dashboard_initializeAIO
} catch {
common_logger "AIO installation failed"
installCommon_rollBack
}

fi

Expand Down