[9.0] (backport #9462) fix: endpoint with tamper protection deb upgrade #9473
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR fixes upgrade and reinstall failures from a deb package involving Elastic Agent and Endpoint by ensuring that the
elastic-agent
service is explicitly stopped before we attempt to stop theendpoint
service or remove its vault directory.Specifically:
preinstall.sh
template so that ifelastic-agent
is running, it is stopped before interacting with Endpoint.PS: thanks to @gabriellandau for pointing out the existence of such an interference
Why is it important?
Without this change, the
elastic-agent
process could continue to invoke Endpoint’sverify
logic in the background during package upgrades.This race condition allowed Endpoint to restart right after being stopped, which recreated the vault directory and led to uninstall/upgrade failures (exit code 28).
By explicitly stopping
elastic-agent
before managing Endpoint, we eliminate these conflicts and make upgrades deterministic and reliable.This restores passing CI for upgrade and reinstall tests across multiple version ranges (e.g. 9.1.2→9.2.0, 9.0.5→9.1.2, 8.18.5→8.19.1).
Checklist
./changelog/fragments
using the changelog toolDisruptive User Impact
No disruptive impact is expected.
The change only affects package preinstall scripts, ensuring the agent is stopped before managing the Endpoint service.
Users upgrading Elastic Agent will benefit from more reliable upgrades without needing to take manual action.
How to test this PR locally
You can either run the respective integration tests or
9.1.2
version of Elastic Agent through deb, enroll it to Fleet and install Defend integration.9.2.0
versionRelated issues
This is an automatic backport of pull request fix: endpoint with tamper protection deb upgrade #9462 done by Mergify.