Add service recovery action 09/129709/2
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Wed, 17 May 2017 20:48:19 +0000 (22:48 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Thu, 18 May 2017 17:20:45 +0000 (19:20 +0200)
For now it's only copy-paste of service restart.
Has to be updated in a future.

Change-Id: I5f13b4f6b1b2c9e62752bb598b51bb1d39826055
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Makefile.am
src/action/service_recover.c [new file with mode: 0644]

index 3212616433fee1a4f702aac3421d4a442f2106bb..c25b279539f746be95d846e3749cb6237e1c3ddd 100644 (file)
@@ -37,6 +37,7 @@ SED_PROCESS = \
 sbin_PROGRAMS = faultd
 faultd_SOURCES = \
     src/action/action_executor.c \
+    src/action/service_recover.c \
     src/action/service_restart.c \
     src/core/event.c \
     src/core/event_processor.c \
diff --git a/src/action/service_recover.c b/src/action/service_recover.c
new file mode 100644 (file)
index 0000000..a722c72
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * faultd
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "action.h"
+#include "action_executor.h"
+#include "decision_made_event.h"
+#include "log.h"
+#include "systemd_dbus.h"
+
+static int recover_service(struct faultd_action *action)
+{
+       struct faultd_event *ev = nqueue_pop(&action->execution_queue,
+                                                                                struct faultd_event, nq_node);
+       struct decision_made_event *dm_ev = to_decision_made_event(ev);
+       int ret;
+
+       /*
+        * TODO:
+        * For now it's just copy paste of service restart
+        * Add some real recovery action here
+        */
+       ret = faultd_dbus_call_systemd_simple((char *)dm_ev->action_data,
+                                                                                 SYSTEMD_UNIT_INTERFACE,
+                                                                                 "Restart",
+                                                                                 "s",
+                                                                                 "replace");
+       if (ret < 0)
+               log_error_errno(ret, "Failed to restart service: %s",
+                                               (char *)dm_ev->action_data);
+
+       faultd_event_unref(ev);
+       return 0;
+}
+
+static struct faultd_action service_recover_action = {
+       .action_id = FAULTD_ACTION_SERVICE_RECOVER_ID,
+       .impl_name = FAULTD_DEFAULT_ACTION_IMPL,
+       .execute = recover_service,
+       .node = LIST_HEAD_INIT(service_recover_action.node),
+};
+
+FAULTD_ACTION_REGISTER_SIMPLE(service_recover_action);