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

Unify unatteded uninstall check tools and start cluster #1221

Open
wants to merge 12 commits into
base: unify-unatteded-uninstall-chose-component
Choose a base branch
from
Open
110 changes: 81 additions & 29 deletions unattended_installer/install_functions/opendistro/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function checkArguments() {
fi

# -------------- Overwrite --------------------------------------

if [ -n "${overwrite}" ] && [ -z "${AIO}" ] && [ -z "${elasticsearch}" ] && [ -z "${kibana}" ] && [ -z "${wazuh}" ]; then
logger -e "The argument -o|--overwrite must be used with -a, -k, -e or -w. If you want to uninstall all the components use -u|--uninstall."
exit 1
Expand Down Expand Up @@ -82,6 +81,7 @@ function checkArguments() {

if [ -n "${wazuhinstalled}" ] || [ -n "${wazuh_remaining_files}" ] || [ -n "${elasticsearchinstalled}" ] || [ -n "${elastic_remaining_files}" ] || [ -n "${filebeatinstalled}" ] || [ -n "${filebeat_remaining_files}" ] || [ -n "${kibanainstalled}" ] || [ -n "${kibana_remaining_files}" ]; then
if [ -n "${overwrite}" ]; then
uninstall_module_name="wazuh"
rollBack
else
logger -e "Some the Wazuh components were found on this host. If you want to overwrite the current installation, run this script back using the option -o/--overwrite. NOTE: This will erase all the existing configuration and data."
Expand All @@ -96,6 +96,7 @@ function checkArguments() {

if [ -n "${elasticsearchinstalled}" ] || [ -n "${elastic_remaining_files}" ]; then
if [ -n "${overwrite}" ]; then
uninstall_module_name="elasticsearch"
rollBack
else
logger -e "Elasticsearch is already installed in this node or some of its files haven't been erased. Use option -o|--overwrite to overwrite all components."
Expand All @@ -109,6 +110,7 @@ function checkArguments() {
if [ -n "${kibana}" ]; then
if [ -n "${kibanainstalled}" ] || [ -n "${kibana_remaining_files}" ]; then
if [ -n "${overwrite}" ]; then
uninstall_module_name="kibana"
rollBack
else
logger -e "Kibana is already installed in this node or some of its files haven't been erased. Use option -o|--overwrite to overwrite all components."
Expand Down Expand Up @@ -141,6 +143,10 @@ function checkArguments() {

# -------------- Cluster start ----------------------------------

if [[ -n "${start_elastic_cluster}" && ( -z "${elasticsearchinstalled}" || -z "${elastic_remaining_files}") ]]; then
logger -e "The argument -s|--start-cluster need elasticsearch installed. Run the script with the parameter first --elasticsearch <elasticsearch-node-name>."
exit 1
fi
if [[ -n "${start_elastic_cluster}" && ( -n "${AIO}" || -n "${elasticsearch}" || -n "${kibana}" || -n "${wazuh}" || -n "${overwrite}" || -n "${configurations}" || -n "${tar_conf}" || -n "${uninstall}") ]]; then
logger -e "The argument -s|--start-cluster can't be used with -a, -k, -e or -w arguments."
exit 1
Expand All @@ -155,42 +161,83 @@ function checkArguments() {

}

function checkTools() {

# -------------- Check tools required to run the script (awk, sed, etc.) -----------------------------------------

toolList=( "awk" "cat" "chown" "cp" "curl" "echo" "export"
"free" "grep" "kill" "mkdir" "mv" "rm" "sed"
"sudo" "tar" "touch" "uname")

missingtoolsList=()
for command in "${toolList[@]}"
do
if [ -z "$(command -v ${command})" ]; then
missingtoolsList+="${command}, "
fi
done

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

logger "---------------------------------- Missing tool -----------------------------------"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger "---------------------------------- Missing tool -----------------------------------"
logger "---------------------------------- Missing tools -----------------------------------"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

logger "Missing tool report: ${missingtoolsList} are not installed. All this command's are necessary for the correct use of this tool."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger "Missing tool report: ${missingtoolsList} are not installed. All this command's are necessary for the correct use of this tool."
logger "The following command or commands are not present in the system: ${missingtoolsList} and must it is / they are necessary for the correct use of this tool."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

exit 1

fi

}

function checkHealth() {

checkSpecs
if [ -n "${elasticsearch}" ]; then
if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then
logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements."
exit 1
else
logger "Check recommended minimum hardware requirements for Elasticsearch done."
fi
if [ -z "${cores}" ]; then
logger -w "The script needs to parse the file '${coresFile}' to check the minimum required hardware of CPU cores."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you plan to exit from the script run, this message is not a warning but an error. Only errors should be able to exit from a run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

logger -w "Use the --ignore-health-check parameter to dismiss the recommended minimum hardware requirements check."
exit 1
fi
if [ -z "${ram_gb}" ]; then
logger - w "The command 'free' is required to check the minimum required hardware of RAM."
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another point: is there any way to reach this code without free installed?
I like the idea of ${ram_gb} not valid value management, but I don't think the message could happen in any situation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the free command was not installed. /proc/meminfo can be used
Although I did not imagine a possible scenario where free was not installed, I preferred to add this check, in case there were any cases.
When I did some research later I found that free and other commands come specifically from a package.

PS: I add a workarrond for the stage that free is not.

logger -w "Use the --ignore-health-check parameter to dismiss the recommended minimum hardware requirements check."
exit 1
fi

if [ -n "${kibana}" ]; then
if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then
logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements."
exit 1
else
logger "Check recommended minimum hardware requirements for Kibana done."
if [ -n "${cores}" ] && [ -n "${ram_gb}" ]; then

if [ -n "${elasticsearch}" ]; then
if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then
logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements."
exit 1
else
logger "Check recommended minimum hardware requirements for Elasticsearch done."
fi
fi
fi

if [ -n "${wazuh}" ]; then
if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 1700 ]; then
logger -e "Your system does not meet the recommended minimum hardware requirements of 2Gb of RAM and 2 CPU cores . If you want to proceed with the installation use the -i option to ignore these requirements."
exit 1
else
logger "Check recommended minimum hardware requirements for Wazuh Manager done."
if [ -n "${kibana}" ]; then
if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then
logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements."
exit 1
else
logger "Check recommended minimum hardware requirements for Kibana done."
fi
fi
fi

if [ -n "${aio}" ]; then
if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then
logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements."
exit 1
else
logger "Check recommended minimum hardware requirements for AIO done."
if [ -n "${wazuh}" ]; then
if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 1700 ]; then
logger -e "Your system does not meet the recommended minimum hardware requirements of 2Gb of RAM and 2 CPU cores . If you want to proceed with the installation use the -i option to ignore these requirements."
exit 1
else
logger "Check recommended minimum hardware requirements for Wazuh Manager done."
fi
fi

if [ -n "${aio}" ]; then
echo "${cores}"
if [ "${cores}" -lt 2 ] || [ "${ram_gb}" -lt 3700 ]; then
logger -e "Your system does not meet the recommended minimum hardware requirements of 4Gb of RAM and 2 CPU cores. If you want to proceed with the installation use the -i option to ignore these requirements."
exit 1
else
logger "Check recommended minimum hardware requirements for AIO done."
fi
fi
fi

Expand Down Expand Up @@ -316,7 +363,12 @@ function checkPreviousCertificates() {

function checkSpecs() {

cores=$(cat /proc/cpuinfo | grep -c processor )
coresFile="/proc/cpuinfo"
if [ -f "$coresFile" ]; then
cores=$(cat "$coresFile" | grep -c processor )
else
logger -e "The $coresFile does not exist."
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
fi
ram_gb=$(free -m | awk '/^Mem:/{print $2}')

}
Expand Down
11 changes: 3 additions & 8 deletions unattended_installer/wazuh_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ function main() {
importFunction "wazuh-cert-tool.sh"
importFunction "wazuh-passwords-tool.sh"

checkTools

logger "Starting Wazuh unattended installer. Wazuh version: ${wazuh_version}. Wazuh installer version: ${wazuh_install_vesion}"

# -------------- Preliminary checks --------------------------------
Expand All @@ -356,6 +358,7 @@ function main() {
# -------------- Uninstall case ------------------------------------

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

importFunction "wazuh.sh"
importFunction "filebeat.sh"
importFunction "elasticsearch.sh"
Expand Down Expand Up @@ -404,14 +407,6 @@ function main() {
checkNames
fi

# -------------- Prerequisites and Wazuh repo ----------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Dependencies installation uneccesary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recovered, this was a mistake

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why is moved before the preliminary steps?
If there is an error with the node names, etc, I prefer to know it before starting installing dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, I do not understand. Tell me if I understand correctly please.
Functions import. Line 332. Check the system tools.
Preliminary checks, Line 345. This step checks arguments and parameters.
Prerequisites and Wazuh repo, Line 375. This step installs dependencies
Preliminary steps, Line 383. It only validates checkPreviousCertificates.
I understand this would be correct.


if [ -n "${AIO}" ] || [ -n "${elasticsearch}" ] || [ -n "${kibana}" ] || [ -n "${wazuh}" ]; then
logger "---------------------------------- Dependencies -----------------------------------"
installPrerequisites
addWazuhrepo
fi

# -------------- Elasticsearch or Start Elasticsearch cluster case---

if [ -n "${elasticsearch}" ] || [ -n "${start_elastic_cluster}" ] ; then
Expand Down