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

Conversation

myu1d157h0u54nd
Copy link
Contributor

@myu1d157h0u54nd myu1d157h0u54nd commented Jan 29, 2022

Related issue
Closes #1212

Description

The script needs to be able to do:

  • Unattended script: check tools (awk, sed, etc.)
  • A check is needed in the "--start-cluster" case.

verdx
verdx previously approved these changes Jan 31, 2022
Copy link
Contributor

@verdx verdx left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@alberpilot alberpilot left a comment

Choose a reason for hiding this comment

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

cores=$(cat /proc/cpuinfo | grep -c processor )
Check if the file exist.

unattended_installer/wazuh_install.sh Outdated Show resolved Hide resolved
"tar"
"awk"
"free"
"sed")
Copy link
Contributor

Choose a reason for hiding this comment

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

Include echo, cat, grep, rm, touch, kill, cp, mv, export, mkdir, curl, chown, sudo, chmod, in the list. Then, don't exit in the first not found command. Instead of this, make a list of not-found dependencies and print the list, avoiding the re-run for every command.

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Installation simulation, modifying the list of tools by adding the false commands 'badbad' and 'notsobad'.

sudo bash /tmp/unattended_installer/wazuh_install.sh --local --development --ignore-health-check --disable-spinner --all-in-one

03/02/2022 16:41:02 INFO: ---------------------------------- Missing tool -----------------------------------
03/02/2022 16:41:02 INFO: Missing tool report: badbad, notsobad,  are not installed. All this command's are necessary for the correct use of this tool.

@myu1d157h0u54nd
Copy link
Contributor Author

/proc/cpuinfo

Done!

Copy link
Contributor

@alberpilot alberpilot left a comment

Choose a reason for hiding this comment

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

Please review the requested changes and please attach examples of changes.

@@ -308,7 +351,12 @@ function checkPreviousCertificates() {

function checkSpecs() {

cores=$(cat /proc/cpuinfo | grep -c processor )
coresFile=/etc/resolv.conf
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
coresFile=/etc/resolv.conf
coresFile="/proc/cpuinfo"

@myu1d157h0u54nd
Copy link
Contributor Author

myu1d157h0u54nd commented Feb 4, 2022

Simulation of a linux where the file does not exist: /proc/cpuinfo. Using the name /proc/cpuinfoTEST

sudo bash /tmp/unattended_installer/wazuh_install.sh --local --development --disable-spinner --all-in-one

03/02/2022 14:51:58 INFO: Starting Wazuh unattended installer. Wazuh version: 4.3.0. Wazuh installer version: 0.1
03/02/2022 14:51:58 INFO: ---------------------------------- Dependencies -----------------------------------
03/02/2022 14:51:58 INFO: Starting the installation of dependencies.
03/02/2022 14:52:14 INFO: Installation of dependencies finished.
03/02/2022 14:52:30 ERROR: The /proc/cpuinfoTEST does not exist.
03/02/2022 14:52:30 WARNING: The script needs to parse the file '/proc/cpuinfoTEST' to check the minimum required hardware of CPU cores.
03/02/2022 14:52:30 WARNING: Use the --ignore-health-check parameter to dismiss the recommended minimum hardware requirements check.

Continuation of the installation process following the recommendation of the script.
bash /tmp/unattended_installer/wazuh_install.sh --local --development --ignore-health-check --disable-spinner --all-in-one

03/02/2022 14:57:27 INFO: Starting Wazuh unattended installer. Wazuh version: 4.3.0. Wazuh installer version: 0.1
03/02/2022 14:57:27 INFO: ---------------------------------- Dependencies -----------------------------------
03/02/2022 14:57:27 INFO: Starting the installation of dependencies.
03/02/2022 14:57:37 INFO: Installation of dependencies finished.
03/02/2022 14:57:43 WARNING: Health-check ignored.
03/02/2022 14:57:44 INFO: ------------------------------- Configuration files -------------------------------
03/02/2022 14:57:44 INFO: Creating the root certificate.
03/02/2022 14:57:45 INFO: Creating the Elasticsearch certificates.
03/02/2022 14:57:45 INFO: Creating the Wazuh server certificates.
03/02/2022 14:57:45 INFO: Creating the Kibana certificate.
03/02/2022 14:57:45 INFO: Configuration files created: /tmp/unattended_installer/configurations.tar
03/02/2022 14:57:45 INFO: -------------------------- Open Distro for Elasticsearch --------------------------
03/02/2022 14:57:45 INFO: Starting Open Distro for Elasticsearch installation.

@myu1d157h0u54nd
Copy link
Contributor Author

Installation simulation, modifying the list of tools by adding the false commands 'badbad' and 'notsobad'.

sudo bash /tmp/unattended_installer/wazuh_install.sh --local --development --ignore-health-check --disable-spinner --all-in-one

03/02/2022 16:41:02 INFO: ---------------------------------- Missing tool -----------------------------------
03/02/2022 16:41:02 INFO: Missing tool report: badbad, notsobad,  are not installed. All this command's are necessary for the correct use of this tool.

Copy link
Contributor

@alberpilot alberpilot left a comment

Choose a reason for hiding this comment

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

Please review the requested changes


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

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

logger "---------------------------------- Missing tool -----------------------------------"
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

@@ -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.

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

exit 1
fi
if [ -z "${ram_gb}" ]; then
logger - w "The command 'free' is required to check the minimum required hardware of RAM."
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.

Copy link
Contributor

@alberpilot alberpilot left a comment

Choose a reason for hiding this comment

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

Please review the requested changes

MEMinKB=$(cat "$memFile" | grep MemTotal | awk '/^MemTotal:/{print $2}')
ram_gb=$(( $MEMinKB / 1024 ))
else
logger -e "The $coresFile does not exist."
Copy link
Contributor

Choose a reason for hiding this comment

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

Why $coresFile?

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 2761821

@@ -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.

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.

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

logger "---------------------------------- Missing tools -----------------------------------"
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

Choose a reason for hiding this comment

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

Suggested change
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."
logger "The following command or commands are not present in the system: ${missingtoolsList}. Those tools 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 2761821

@myu1d157h0u54nd
Copy link
Contributor Author

Pending conflict resolution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants