Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions modules/gghealthd/src/health.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ GglError gghealthd_restart_component(GglBuffer component_name) {
return GGL_ERR_FAILURE;
}

reset_restart_counters((char *) qualified_name);

sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *reply = NULL;
int ret = sd_bus_call_method(
Expand Down Expand Up @@ -215,32 +217,6 @@ GglError gghealthd_restart_component(GglBuffer component_name) {
return translate_dbus_call_error(ret);
}

// Reset systemd failure counter after successful restart
sd_bus_error reset_error = SD_BUS_ERROR_NULL;
sd_bus_message *reset_reply = NULL;
int reset_ret = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"ResetFailedUnit",
&reset_error,
&reset_reply,
"s",
(char *) qualified_name
);
GGL_CLEANUP(sd_bus_error_free, reset_error);
GGL_CLEANUP(sd_bus_message_unrefp, reset_reply);

if (reset_ret < 0) {
GGL_LOGW(
"Failed to reset failure counter for %.*s (errno=%d)",
(int) component_name.len,
component_name.data,
-reset_ret
);
}

GGL_LOGI(
"Successfully restarted component %.*s",
(int) component_name.len,
Expand All @@ -250,6 +226,7 @@ GglError gghealthd_restart_component(GglBuffer component_name) {
}

GglError gghealthd_init(void) {
reset_restart_counters(NULL);
sd_notify(0, "READY=1");
init_health_events();
return GGL_ERR_OK;
Expand Down
46 changes: 46 additions & 0 deletions modules/gghealthd/src/sd_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,49 @@ GglError get_lifecycle_state(
err = get_component_result(bus, unit_path, state);
return err;
}

void reset_restart_counters(const char *qualified_name) {
sd_bus *bus = NULL;
GglError err = open_bus(&bus);
GGL_CLEANUP(sd_bus_unrefp, bus);
if (err != GGL_ERR_OK) {
return;
}
sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *reply = NULL;

int ret;
if (qualified_name != NULL) {
ret = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"ResetFailedUnit",
&error,
&reply,
"s",
qualified_name
);
} else {
ret = sd_bus_call_method(
bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"ResetFailed",
&error,
&reply,
""
);
}
if (ret < 0) {
GGL_LOGW(
"Failed to reset failure counter for %s (errno=%d)",
qualified_name,
-ret
);
}
GGL_CLEANUP(sd_bus_error_free, error);
GGL_CLEANUP(sd_bus_message_unrefp, reply);
}
4 changes: 4 additions & 0 deletions modules/gghealthd/src/sd_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ GglError get_unit_path(
const char **unit_path
);

// equivalent to systemd reset-failed <service-name>
// if qualified_name is NULL, then a global reset-failed is issued
void reset_restart_counters(const char *qualified_name);

GglError open_bus(sd_bus **bus);

GglError get_service_name(GglBuffer component_name, GglBuffer *qualified_name);
Expand Down