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

Preserve previous state of wazuh-indexer.service on upgrade #487

Open
Tracked by #484
AlexRuiz7 opened this issue Oct 22, 2024 · 2 comments · May be fixed by #492
Open
Tracked by #484

Preserve previous state of wazuh-indexer.service on upgrade #487

AlexRuiz7 opened this issue Oct 22, 2024 · 2 comments · May be fixed by #492
Assignees
Labels
level/subtask Subtask issue type/enhancement Enhancement issue

Comments

@AlexRuiz7
Copy link
Member

Description

We are aiming for a consistent behavior of our packages during the lifecycle. Unlike the wazuh-agent and wazuh-manager services, our service does not preserve the previous state of the service when performing an upgrade. The service must be enabled and restarted manually afterward.

The wazuh-indexer post installation scripts must be updated to preserve the previous service status, as other Wazuh central components packages do.

Expected behavior

Before update After update
wazuh-indexer.service stopped wazuh-indexer.service stopped
wazuh-indexer.service running wazuh-indexer.service running
@AlexRuiz7 AlexRuiz7 added level/subtask Subtask issue type/enhancement Enhancement issue labels Oct 22, 2024
@QU3B1M QU3B1M self-assigned this Oct 23, 2024
@QU3B1M QU3B1M linked a pull request Oct 24, 2024 that will close this issue
3 tasks
@QU3B1M
Copy link
Member

QU3B1M commented Oct 24, 2024

Inspired in the solution applied in the Wazuh-manager and Wazuh-agent packages, the implementation consists in saving a temp file as reference to the previous status of the service at the pre-install stage (preinst), and a conditional that restores the running status of the Wazuh-indexer service at the post-install stage (postinst).

  • Pre-install script additions
    ...
    # Reference to restore actual service status
    restart_service=/tmp/wazuh-indexer.restart
    
    # Stop existing service
    if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer.service >/dev/null; then
        ...
        touch $restart_service
    fi
    ...
  • Post-install script additions
    ...
    if [ -f $restart_service ]; then
        rm -f $restart_service
        echo "Restarting wazuh-indexer service..."
        if command -v systemctl > /dev/null; then
            systemctl restart wazuh-indexer.service > /dev/null 2>&1
        fi
        exit 0
    fi
    ...

Also the Pre-remove is updated to avoid running the service stop when the package is being upgraded

case "$1" in
    upgrade|deconfigure)
    ;;
    remove)
        echo "Running Wazuh Indexer Pre-Removal Script"
        # Stop existing service
        ...
    ;;
    failed-upgrade)
    ;;
    *)
        echo "prerm called with unknown argument \`$1'" >&2
        exit 0
    ;;
esac

@QU3B1M
Copy link
Member

QU3B1M commented Oct 25, 2024

Upgrading a running Wazuh-indexer using the package with the solution implemented results on the package running.

  • Previous Wazuh-indexer status
    systemctl status wazuh-indexer
    
    ● wazuh-indexer.service - wazuh-indexer
         Loaded: loaded (/lib/systemd/system/wazuh-indexer.service; enabled; preset>
         Active: active (running) since Fri 2024-10-25 05:06:51 PDT; 13min ago
           Docs: https://documentation.wazuh.com
       Main PID: 3737 (java)
          Tasks: 76 (limit: 4571)
         Memory: 1.3G
            CPU: 27.348s
         CGroup: /system.slice/wazuh-indexer.service
                 └─3737 /usr/share/wazuh-indexer/jdk/bin/java -Xshare:auto -Dopense>
  • Upgrade Wazuh-indexer
    dpkg -i wazuh-indexer_5.0.0-0_arm64_b2d1265.deb 
    
    (Reading database ... 151060 files and directories currently installed.)
    Preparing to unpack wazuh-indexer_5.0.0-0_arm64_b2d1265.deb ...
    Running Wazuh Indexer Pre-Installation Script
    Stop existing wazuh-indexer.service
    Unpacking wazuh-indexer (5.0.0-0) over (5.0.0-0) ...
    Setting up wazuh-indexer (5.0.0-0) ...
    Running Wazuh Indexer Post-Installation Script
    Restarting wazuh-indexer service...
  • Status after upgrade
    systemctl status wazuh-indexer
    
    ● wazuh-indexer.service - wazuh-indexer
         Loaded: loaded (/lib/systemd/system/wazuh-indexer.service; enabled; preset>
         Active: active (running) since Fri 2024-10-25 05:23:58 PDT; 1min 30s ago
           Docs: https://documentation.wazuh.com
       Main PID: 4051 (java)
          Tasks: 81 (limit: 4571)
         Memory: 1.3G
            CPU: 14.959s
         CGroup: /system.slice/wazuh-indexer.service
                 └─4051 /usr/share/wazuh-indexer/jdk/bin/java -Xshare:auto -Dopense>    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level/subtask Subtask issue type/enhancement Enhancement issue
Projects
Status: Pending final review
Development

Successfully merging a pull request may close this issue.

2 participants