-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add support for agent self-restarting for Linux #77
Comments
Update[2024-08-12] I started doing some research on how to implement it. |
2024-12-03
2024-12-04
[DEBUG] 1000: execute_process(curl --fail -L https://gitlab.gnome.org//GNOME/libxml2/-/archive/v2.11.7/libxml2-v2.11.7.tar.gz --create-dirs --output /build_wazuh/agent/wazuh-agent-5.0.0/src/vcpkg/downloads/GNOME-libxml2-v2.11.7.tar.gz.34390.part)
[DEBUG] 1000: cmd_execute_and_stream_data() returned 22 after 4244993 us
error: Missing GNOME-libxml2-v2.11.7.tar.gz and downloads are blocked by x-block-origin.
error: https://gitlab.gnome.org//GNOME/libxml2/-/archive/v2.11.7/libxml2-v2.11.7.tar.gz: curl failed to download with exit code 22
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
curl: (22) The requested URL returned error: 503
[DEBUG] /source/src/vcpkg/base/downloads.cpp(1030):
[DEBUG] Time in subprocesses: 4244993us
[DEBUG] Time in parsing JSON: 2us
[DEBUG] Time in JSON reader: 0us
[DEBUG] Time in filesystem: 749us
[DEBUG] Time in loading ports: 0us
[DEBUG] Exiting after 4.2 s (4245307us) Sadly, it looks like a temporary issue. However, I found a link that might provide some clues about what is happening. For now, I haven’t found a solution and can only wait for the server to become unblocked.
2024-12-05
2024-12-06
2024-12-09
2024-12-10
2024-12-11
|
2024-12-12
Option 1: fork(), execl() y setpgid()void RestartAgent(const std::string& configFile, const char* programPath) {
LogInfo("Restart: Stopping wazuh-agent.");
StopAgent(configFile);
int timeoutSeconds = 20;
auto startTime = std::chrono::steady_clock::now();
while ( "stopped" != unix_daemon::GetDaemonStatus(configFile) ) {
auto elapsed = std::chrono::steady_clock::now() - startTime;
if (std::chrono::duration_cast<std::chrono::seconds>(elapsed).count() > timeoutSeconds) {
LogError("Timeout reached while stopping wazuh-agent.");
return ;
}
LogInfo("Waiting for wazuh-agent to stop...");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
LogInfo("Restart: starting wazuh agent.");
pid_t pid = fork();
if (pid == 0) {
// Child process
execl(programPath, programPath, nullptr);
exit(1);
} else if (pid < 0) {
LogError("Fork failed");
exit(1);
} else {
// Parent process
setpgid(pid, pid);
exit(0);
}
} Option 2: Use execl()void RestartAgent(const std::string& configFile, const char* programPath) {
LogInfo("Restart: Stopping wazuh-agent.");
StopAgent(configFile); // The parent process handles the stop signal
int timeoutSeconds = 20;
auto startTime = std::chrono::steady_clock::now();
LogInfo("Waiting for wazuh-agent to stop...");
while ( "stopped" != unix_daemon::GetDaemonStatus(configFile) ) {
auto elapsed = std::chrono::steady_clock::now() - startTime;
if (std::chrono::duration_cast<std::chrono::seconds>(elapsed).count() > timeoutSeconds) {
LogError("Restart: Timeout reached while stopping wazuh-agent.");
return ;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
LogInfo("Restart: starting wazuh agent.");
execl(programPath, programPath, nullptr);
} Option 3: Maintain the same process and return to a StartAgentvoid RestartAgent(const std::string& configFile)
{
LogInfo("Restart: Stoping wazuh-agent.");
StopAgent(configFile);
int timeoutSeconds = 20;
auto startTime = std::chrono::steady_clock::now();
while ( "stopped" != unix_daemon::GetDaemonStatus(configFile) ) {
auto elapsed = std::chrono::steady_clock::now() - startTime;
// Check elapsed time
if (std::chrono::duration_cast<std::chrono::seconds>(elapsed).count() > timeoutSeconds) {
LogError("Timeout reached while stopping wazuh-agent.");
return ;
}
LogInfo("Waiting wazuh-agent... be stopped.");
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
LogInfo("Restart: starting wazuh agent.");
StartAgent(configFile);
} 2024-12-13
2024-12-16
2024-12-19
2024-12-20
The issue could look something like this: %%{init: {'themeVariables': {'maxWidth': '300px'}}}%%
graph TD
A[Agent] --> B[Task Manager]
B --> D[Module Manager]
B --> E[Communicator]
B --> F[Command Handler]
F --> C[Self-Restart]
C -->|Fails| G[Blocked Process <br/> Unable to Respond]
G --> H[Unable to Kill the Process, <br/> Losing Control of the Process]
A possible solution would be to implement something like this: %%{init: {'themeVariables': {'maxWidth': '300px'}}}%%
graph TD
A[Agent] --> B[Task Manager]
B --> D[Module Manager]
B --> E[Communicator]
B --> F[Command Handler]
F --> C[Self-Restart]
subgraph Monitoring
M[Monitoring Process]
T[Timeout - 30 seconds]
K[Kill Blocked Process]
N[Start New Agent]
end
C -->|Fails| G[Blocked Process <br/> Unable to Respond]
G --> H[Unable to Kill the Process, <br/> Losing Control of the Process]
C -->|Sent to Monitor| M
M --> T
T -->|If >30s| K
K -->|Kills| A
K --> N
N --> B[Task Manager]
2024-12-23
2025-01-13
|
2025-01-21
2025-01-22
2025-01-23
2025-01-24
2025-01-25
|
Parent issue:
Description
We can now start working on the implementation based on the design phase in the issue #63.
Functional requirements
Non-functional requirements
Implementation restrictions
The text was updated successfully, but these errors were encountered: