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 state of wazuh-indexer service on upgrade #492

Closed
wants to merge 3 commits into from

Conversation

QU3B1M
Copy link
Member

@QU3B1M QU3B1M commented Oct 24, 2024

Description

Update wazuh-indexer pre, and post installation scripts to preserve the previous service status, maintaining consistency with the rest of Wazuh central components packages.

Related Issues

Resolves #487

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.


Testing evidence

Upgrade .deb package validation

  1. Upgrade with service running
    • Service is running before upgrade
      systemctl status wazuh-indexer
      ● wazuh-indexer.service - wazuh-indexer
           Loaded: loaded (/lib/systemd/system/wazuh-indexer.service; enabled; preset: enabled)
           Active: active (running) since Fri 2024-10-25 07:22:28 PDT; 7s ago
             Docs: https://documentation.wazuh.com
         Main PID: 4018 (java)
            Tasks: 72 (limit: 4571)
           Memory: 1.4G
              CPU: 14.054s
           CGroup: /system.slice/wazuh-indexer.service
                   └─4018 /usr/share/wazuh-indexer/jdk/bin/java -Xshare:auto -Dopensearch.networkaddress.cache.ttl=60 -Dope>
    • 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_da70239.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...
    • Service is running after upgrade
      systemctl status wazuh-indexer
      ● wazuh-indexer.service - wazuh-indexer
           Loaded: loaded (/lib/systemd/system/wazuh-indexer.service; enabled; preset: enabled)
           Active: active (running) since Fri 2024-10-25 07:23:23 PDT; 7s ago
             Docs: https://documentation.wazuh.com
         Main PID: 4313 (java)
            Tasks: 73 (limit: 4571)
           Memory: 1.3G
              CPU: 13.464s
           CGroup: /system.slice/wazuh-indexer.service
                   └─4313 /usr/share/wazuh-indexer/jdk/bin/java -Xshare:auto -Dopensearch.networkaddress.cache.ttl=60 -Dope>
  2. Upgrade with service stopped
    • Service is stopped before upgrade
      systemctl status wazuh-indexer
      ○ wazuh-indexer.service - wazuh-indexer
           Loaded: loaded (/lib/systemd/system/wazuh-indexer.service; enabled; preset: enabled)
           Active: inactive (dead) since Fri 2024-10-25 07:25:05 PDT; 8s ago
         Duration: 1min 41.067s
             Docs: https://documentation.wazuh.com
          Process: 4313 ExecStart=/usr/share/wazuh-indexer/bin/systemd-entrypoint -p ${PID_DIR}/wazuh-indexer.pid --quiet (>
         Main PID: 4313 (code=exited, status=143)
              CPU: 16.562s
    • Upgrade wazuh-indexer
      (Reading database ... 151060 files and directories currently installed.)
      Preparing to unpack wazuh-indexer_5.0.0-0_arm64_da70239.deb ...
      Running Wazuh Indexer Pre-Installation Script
      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
      ### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using systemd
       sudo systemctl daemon-reload
       sudo systemctl enable wazuh-indexer.service
      ### You can start wazuh-indexer service by executing
       sudo systemctl start wazuh-indexer.service
      
    • Service is stopped after upgrade
      systemctl status wazuh-indexer
      ○ wazuh-indexer.service - wazuh-indexer
           Loaded: loaded (/lib/systemd/system/wazuh-indexer.service; enabled; preset: enabled)
           Active: inactive (dead) since Fri 2024-10-25 07:25:05 PDT; 19s ago
         Duration: 1min 41.067s
             Docs: https://documentation.wazuh.com
         Main PID: 4313 (code=exited, status=143)
              CPU: 16.562s

Upgrade .rpm package validation

  1. Upgrade with service running
    • Service is running before upgrade
      systemctl status wazuh-indexer
      ● wazuh-indexer.service - wazuh-indexer
           Loaded: loaded (/usr/lib/systemd/system/wazuh-indexer.service; disabled; preset: disabled)
           Active: active (running) since Fri 2024-10-25 14:14:44 -03; 1min 4s ago
             Docs: https://documentation.wazuh.com
         Main PID: 38161 (java)
            Tasks: 69 (limit: 22569)
           Memory: 1.3G
              CPU: 15.619s
           CGroup: /system.slice/wazuh-indexer.service
                   └─38161 /usr/share/wazuh-indexer/jdk/bin/java -Xshare:auto -Dopensearch.networkaddress.cache.ttl=60 -Dop>
      
    • Upgrade wazuh-indexer
      rpm -i wazuh-indexer_5.0.0-0_aarch64_da70239.rpm --force 
      Stop existing wazuh-indexer.service
      Restarting wazuh-indexer service...
      
    • Service is running after upgrade
      ● wazuh-indexer.service - wazuh-indexer
           Loaded: loaded (/usr/lib/systemd/system/wazuh-indexer.service; disabled; preset: disabled)
           Active: active (running) since Fri 2024-10-25 14:31:53 -03; 14s ago
             Docs: https://documentation.wazuh.com
         Main PID: 38490 (java)
            Tasks: 72 (limit: 22569)
           Memory: 1.4G
              CPU: 13.157s
           CGroup: /system.slice/wazuh-indexer.service
                   └─38490 /usr/share/wazuh-indexer/jdk/bin/java -Xshare:auto -Dopensearch.networkaddress.cache.ttl=60 -Dop>
      
      
  2. Upgrade with service stopped
    • Service is stopped before upgrade
      systemctl status wazuh-indexer
      ○ wazuh-indexer.service - wazuh-indexer
           Loaded: loaded (/usr/lib/systemd/system/wazuh-indexer.service; disabled; preset: disabled)
           Active: inactive (dead)
             Docs: https://documentation.wazuh.com
    • Upgrade wazuh-indexer
      rpm -i wazuh-indexer_5.0.0-0_aarch64_da70239.rpm --force 
      ### NOT starting on installation, please execute the following statements to configure wazuh-indexer service to start automatically using systemd
       sudo systemctl daemon-reload
       sudo systemctl enable wazuh-indexer.service
      ### You can start wazuh-indexer service by executing
       sudo systemctl start wazuh-indexer.service
      
    • Service is stopped after upgrade
      systemctl status wazuh-indexer
      ○ wazuh-indexer.service - wazuh-indexer
           Loaded: loaded (/usr/lib/systemd/system/wazuh-indexer.service; disabled; preset: disabled)
           Active: inactive (dead)
             Docs: https://documentation.wazuh.com

@QU3B1M QU3B1M self-assigned this Oct 24, 2024
@QU3B1M QU3B1M requested a review from a team as a code owner October 24, 2024 15:39
@QU3B1M QU3B1M force-pushed the ci/487-preserve-status-of-service branch from 6dc22c9 to 35fc1e1 Compare October 24, 2024 20:03
@QU3B1M QU3B1M force-pushed the ci/487-preserve-status-of-service branch from 35fc1e1 to b2d1265 Compare October 24, 2024 20:51
Copy link
Member

@AlexRuiz7 AlexRuiz7 left a comment

Choose a reason for hiding this comment

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

LGTM. However, consider these comments before we merge.

@QU3B1M
Copy link
Member Author

QU3B1M commented Oct 28, 2024

Update regarding systemd-tmpfiles:

The tool is already used in our distribution scripts, anyway the implementation for our .restart temp is not that straightforward.

Currently systemd-tmpfiles is used in the postinst stage for every scenario (install|upgrade) which is inconvenient since we need to create the .restart file only in the cases where the service is running before the upgrade, detecting and defining it in the preinst step.

Possible implementation:
We could update the preinst script to declare into the wazuh-indexer.conf the creation of the .restart file on the required cases with something like

if command -v systemctl >/dev/null && systemctl is-active wazuh-indexer.service >/dev/null; then
    echo "Stop existing wazuh-indexer.service"
    systemctl --no-reload stop wazuh-indexer.service
    echo "f    /tmp/wazuh-indexer.restart   0750 wazuh-indexer wazuh-indexer - -" >> /usr/lib/sysctl.d/wazuh-indexer.conf

Anyway we must keep the manual removal of the file after the service restart, contemplating the scenario where the user does not power off the system between upgrades.

By manual removal I refer to this if statement

if [ -f %{tmp_dir}/wazuh-indexer.restart ]; then
    rm -f %{tmp_dir}/wazuh-indexer.restart

Conclusion

The implementation of the tool won't help us simplifying the code nor making it clearer for the reader.

@AlexRuiz7 AlexRuiz7 changed the base branch from master to 4.10.0 October 28, 2024 15:14
@AlexRuiz7 AlexRuiz7 changed the base branch from 4.10.0 to master October 28, 2024 15:15
Copy link
Member

@AlexRuiz7 AlexRuiz7 left a comment

Choose a reason for hiding this comment

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

Needs to be ported to 4.10.0.

@QU3B1M
Copy link
Member Author

QU3B1M commented Oct 28, 2024

Ported to > #498

@QU3B1M QU3B1M closed this Oct 28, 2024
@AlexRuiz7 AlexRuiz7 deleted the ci/487-preserve-status-of-service branch October 29, 2024 15:37
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.

Preserve previous state of wazuh-indexer.service on upgrade
3 participants