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

Conversation

fcaffieri
Copy link
Member

Related issue
closes #1736

Description

SE adds new functionality to generate try-catch blocks to handle unexpected errors.
With this PR it is tried that the installation script executes the rollback in case of unexpected failures, such as those reported in the related issue.

Logs example

07/07/2022 10:29:53 INFO: Starting Filebeat installation.
07/07/2022 10:30:07 INFO: Filebeat installation finished.
chmod: cannot access '/etc/filebeat/wazuh-template.json': No such file or directory

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
Created filebeat keystore
Successfully updated the keystore
Successfully updated the keystore
07/07/2022 10:30:07 INFO: Filebeat post-install configuration finished.
07/07/2022 10:30:07 INFO: Starting service filebeat.
07/07/2022 10:30:07 INFO: filebeat service started.

Tests

Test forcing error without verbose:

[root@manager-wpk vagrant]# bash ./wazuh-install-with-try-2.sh -ws wazuh-1 
22/07/2022 11:23:06 INFO: Starting Wazuh installation assistant. Wazuh version: 4.3.6
22/07/2022 11:23:06 INFO: Verbose logging redirected to /var/log/wazuh-install.log
22/07/2022 11:23:13 INFO: Wazuh repository added.
22/07/2022 11:23:13 INFO: --- Wazuh server ---
22/07/2022 11:23:13 INFO: Starting the Wazuh manager installation.
22/07/2022 11:23:55 INFO: Wazuh manager installation finished.
22/07/2022 11:23:55 INFO: Starting service wazuh-manager.
22/07/2022 11:24:10 INFO: wazuh-manager service started.
22/07/2022 11:24:10 INFO: Starting Filebeat installation.
22/07/2022 11:24:17 INFO: Filebeat installation finished.
22/07/2022 11:24:17 INFO: Filebeat installation failed
22/07/2022 11:24:17 INFO: --- Removing existing Wazuh installation ---
22/07/2022 11:24:17 INFO: Removing Filebeat.
22/07/2022 11:24:18 INFO: Filebeat removed.
22/07/2022 11:24:18 INFO: Installation cleaned. Check the /var/log/wazuh-install.log file to learn more about the issue.
22/07/2022 11:24:18 INFO: Installation finished.
[root@manager-wpk vagrant]# sh ./wazuh-install-with-try-2.sh -u
22/07/2022 11:25:28 INFO: Starting Wazuh installation assistant. Wazuh version: 4.3.6
22/07/2022 11:25:28 INFO: Verbose logging redirected to /var/log/wazuh-install.log
22/07/2022 11:25:31 INFO: Filebeat not found in the system so it was not uninstalled.
22/07/2022 11:25:31 INFO: Wazuh indexer not found in the system so it was not uninstalled.
22/07/2022 11:25:31 INFO: Wazuh dashboard not found in the system so it was not uninstalled.
22/07/2022 11:25:31 INFO: Removing Wazuh manager.
22/07/2022 11:25:49 INFO: Wazuh manager removed.
[root@manager-wpk vagrant]# 

Test forcing error with verbose:

[root@manager-wpk vagrant]# 
[root@manager-wpk vagrant]# bash ./wazuh-install-with-try-2.sh -ws wazuh-1 -v 
22/07/2022 11:25:59 INFO: Starting Wazuh installation assistant. Wazuh version: 4.3.6
22/07/2022 11:25:59 INFO: Verbose logging redirected to /var/log/wazuh-install.log
22/07/2022 11:26:05 DEBUG: Adding the Wazuh repository.
[wazuh]
gpgcheck=1
gpgkey=https://packages.wazuh.com/key/GPG-KEY-WAZUH
enabled=1
name=EL-${releasever} - Wazuh
baseurl=https://packages.wazuh.com/4.x/yum/
protect=1
22/07/2022 11:26:06 INFO: Wazuh repository added.
22/07/2022 11:26:06 INFO: --- Wazuh server ---
22/07/2022 11:26:06 INFO: Starting the Wazuh manager installation.
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.zero.com.ar
 * extras: mirrors.eze.sysarmy.com
 * updates: mirrors.eze.sysarmy.com
Resolving Dependencies
--> Running transaction check
---> Package wazuh-manager.x86_64 0:4.3.6-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch            Version            Repository      Size
================================================================================
Installing:
 wazuh-manager          x86_64          4.3.6-1            wazuh          114 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 114 M
Installed size: 437 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wazuh-manager-4.3.6-1.x86_64                                 1/1 
  Verifying  : wazuh-manager-4.3.6-1.x86_64                                 1/1 

Installed:
  wazuh-manager.x86_64 0:4.3.6-1                                                

Complete!
22/07/2022 11:26:45 INFO: Wazuh manager installation finished.
22/07/2022 11:26:45 INFO: Starting service wazuh-manager.
Created symlink from /etc/systemd/system/multi-user.target.wants/wazuh-manager.service to /usr/lib/systemd/system/wazuh-manager.service.
22/07/2022 11:27:00 INFO: wazuh-manager service started.
22/07/2022 11:27:00 INFO: Starting Filebeat installation.
Failed to set locale, defaulting to C
22/07/2022 11:27:05 INFO: Filebeat installation finished.
chmod: cannot access '/etc/filebeat/wazuh-template.json': No such file or directory
22/07/2022 11:27:05 INFO: Filebeat installation failed
22/07/2022 11:27:05 INFO: --- Removing existing Wazuh installation ---
22/07/2022 11:27:05 INFO: Removing Filebeat.
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package filebeat.x86_64 0:7.10.2-1 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package            Arch             Version             Repository        Size
================================================================================
Removing:
 filebeat           x86_64           7.10.2-1            @wazuh            70 M

Transaction Summary
================================================================================
Remove  1 Package

Installed size: 70 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : filebeat-7.10.2-1.x86_64                                     1/1 
  Verifying  : filebeat-7.10.2-1.x86_64                                     1/1 

Removed:
  filebeat.x86_64 0:7.10.2-1                                                    

Complete!
22/07/2022 11:27:06 INFO: Filebeat removed.
22/07/2022 11:27:06 INFO: Installation cleaned. Check the /var/log/wazuh-install.log file to learn more about the issue.
22/07/2022 11:27:06 INFO: Installation finished.
[root@manager-wpk vagrant]# bash ./wazuh-install-with-try-2.sh -u            
22/07/2022 11:42:27 INFO: Starting Wazuh installation assistant. Wazuh version: 4.3.6
22/07/2022 11:42:27 INFO: Verbose logging redirected to /var/log/wazuh-install.log
22/07/2022 11:42:29 INFO: Filebeat not found in the system so it was not uninstalled.
22/07/2022 11:42:29 INFO: Wazuh indexer not found in the system so it was not uninstalled.
22/07/2022 11:42:29 INFO: Wazuh dashboard not found in the system so it was not uninstalled.
22/07/2022 11:42:29 INFO: Removing Wazuh manager.
22/07/2022 11:42:45 INFO: Wazuh manager removed.
[root@manager-wpk vagrant]# 

Test finish ok:

[root@manager-wpk vagrant]# vi wazuh-install-with-try-2.sh 
[root@manager-wpk vagrant]# bash ./wazuh-install-with-try-2.sh -ws wazuh-1 -v
22/07/2022 11:44:29 INFO: Starting Wazuh installation assistant. Wazuh version: 4.3.6
22/07/2022 11:44:29 INFO: Verbose logging redirected to /var/log/wazuh-install.log
22/07/2022 11:44:35 DEBUG: Adding the Wazuh repository.
[wazuh]
gpgcheck=1
gpgkey=https://packages.wazuh.com/key/GPG-KEY-WAZUH
enabled=1
name=EL-${releasever} - Wazuh
baseurl=https://packages.wazuh.com/4.x/yum/
protect=1
22/07/2022 11:44:35 INFO: Wazuh repository added.
22/07/2022 11:44:35 INFO: --- Wazuh server ---
22/07/2022 11:44:35 INFO: Starting the Wazuh manager installation.
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.zero.com.ar
 * extras: mirrors.eze.sysarmy.com
 * updates: mirrors.eze.sysarmy.com
Resolving Dependencies
--> Running transaction check
---> Package wazuh-manager.x86_64 0:4.3.6-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch            Version            Repository      Size
================================================================================
Installing:
 wazuh-manager          x86_64          4.3.6-1            wazuh          114 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 114 M
Installed size: 437 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wazuh-manager-4.3.6-1.x86_64                                 1/1 
  Verifying  : wazuh-manager-4.3.6-1.x86_64                                 1/1 

Installed:
  wazuh-manager.x86_64 0:4.3.6-1                                                

Complete!
22/07/2022 11:45:12 INFO: Wazuh manager installation finished.
22/07/2022 11:45:12 INFO: Starting service wazuh-manager.
Created symlink from /etc/systemd/system/multi-user.target.wants/wazuh-manager.service to /usr/lib/systemd/system/wazuh-manager.service.
22/07/2022 11:45:27 INFO: wazuh-manager service started.
22/07/2022 11:45:27 INFO: Starting Filebeat installation.
Failed to set locale, defaulting to C
22/07/2022 11:45:32 INFO: Filebeat installation finished.
wazuh/alerts/
wazuh/alerts/config/
wazuh/alerts/config/alerts.yml
wazuh/alerts/manifest.yml
wazuh/alerts/ingest/
wazuh/alerts/ingest/pipeline.json
wazuh/archives/
wazuh/archives/config/
wazuh/archives/config/archives.yml
wazuh/archives/manifest.yml
wazuh/archives/ingest/
wazuh/archives/ingest/pipeline.json
wazuh/module.yml
Created filebeat keystore
Successfully updated the keystore
Successfully updated the keystore
22/07/2022 11:45:33 INFO: Filebeat post-install configuration finished.
22/07/2022 11:45:33 DEBUG: Setting Wazuh indexer cluster passwords.
Successfully updated the keystore
22/07/2022 11:45:37 DEBUG: filebeat started
22/07/2022 11:45:39 INFO: Starting service filebeat.
Created symlink from /etc/systemd/system/multi-user.target.wants/filebeat.service to /usr/lib/systemd/system/filebeat.service.
22/07/2022 11:45:39 INFO: filebeat service started.
22/07/2022 11:45:39 INFO: Installation finished.
[root@manager-wpk vagrant]# 

@fcaffieri fcaffieri self-assigned this Jul 22, 2022
@fcaffieri fcaffieri linked an issue Jul 22, 2022 that may be closed by this pull request
@okynos okynos requested review from DFolchA and okynos July 25, 2022 11:03
@fcaffieri fcaffieri changed the base branch from master to 4.3 September 12, 2022 11:52
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.

Filebeat rollback error on unattended installation
1 participant