Add support for agent self-restarting: Development Phase #386
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.
Description
This PR introduces the initial development phase for implementing self-restarting functionality in the agent. The feature involves the agent detecting a failure in its processes and triggering a self-restart to ensure continuous operation. The core of the implementation relies on enhancing the existing task and module management systems and integrating a monitoring process to handle agent failures.
Implementation Details:
The self-restarting feature follows this high-level process flow:
Test
Server
I used the Python mock server
With the following command, I initialize the self-restart.
wazuh-agent/# echo '{"commands": [{"document_id": "1a96a0ab", "action": {"name": "restart", "version": "v5.0.0", "args": ""}, "target": {"type": "agent", "id": "1a96a0ab-5bef-415c-bb3c-ea3e294215a0"}, "status": "sent"}]}' > src/agent/testtool/mock_server/responses/commands.json
Agent
Configure the agent to use the server address:
Logs
Minor changes:
Pending Tasks:
Improve Signal Handler: Refactor the signal handler to use a unified class structure for better maintainability and extensibility.
Test Self-Restart using systemctl: Add tests to verify the self-restarting feature works as expected when controlled by systemctl.
Refactor Agent Startup: Simplify the fork logic in the agent’s startup sequence by creating a dedicated function for process creation, improving readability and reducing complexity.