chiark / gitweb /
systemctl: introduce reset-maintenance command
[elogind.git] / src / service.c
index f8b4ff6a246d5c9c5044d2be243513f81f8fa191..6b786d1bb124c141dfa3dddfdebd3af05cd519dc 100644 (file)
@@ -1179,6 +1179,11 @@ static void service_set_state(Service *s, ServiceState state) {
                 service_connection_unref(s);
         }
 
+        /* For the inactive states unit_notify() will trim the cgroup,
+         * but for exit we have to do that ourselves... */
+        if (state == SERVICE_EXITED)
+                cgroup_bonding_trim_list(s->meta.cgroup_bondings, true);
+
         if (old_state != state)
                 log_debug("%s changed %s -> %s", s->meta.id, service_state_to_string(old_state), service_state_to_string(state));
 
@@ -1841,7 +1846,8 @@ static void service_run_next(Service *s, bool success) {
                                false,
                                !s->permissions_start_only,
                                !s->root_directory_start_only,
-                               false,
+                               s->control_command_id == SERVICE_EXEC_START_PRE ||
+                               s->control_command_id == SERVICE_EXEC_STOP_POST,
                                false,
                                &s->control_pid)) < 0)
                 goto fail;
@@ -1890,6 +1896,14 @@ static int service_start(Unit *u) {
                 return -ECANCELED;
         }
 
+        if ((s->exec_context.std_input == EXEC_INPUT_SOCKET ||
+             s->exec_context.std_output == EXEC_OUTPUT_SOCKET ||
+             s->exec_context.std_error == EXEC_OUTPUT_SOCKET) &&
+            s->socket_fd < 0) {
+                log_warning("%s can only be started with a per-connection socket.", u->meta.id);
+                return -EINVAL;
+        }
+
         s->failure = false;
         s->main_pid_known = false;
         s->allow_restart = true;
@@ -2185,7 +2199,8 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
                                 success = true;
                 }
 
-                log_debug("%s: main process exited, code=%s, status=%i", u->meta.id, sigchld_code_to_string(code), status);
+                log_full(success ? LOG_DEBUG : LOG_NOTICE,
+                         "%s: main process exited, code=%s, status=%i", u->meta.id, sigchld_code_to_string(code), status);
                 s->failure = s->failure || !success;
 
                 /* The service exited, so the service is officially
@@ -2242,7 +2257,8 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
 
                 s->control_pid = 0;
 
-                log_debug("%s: control process exited, code=%s status=%i", u->meta.id, sigchld_code_to_string(code), status);
+                log_full(success ? LOG_DEBUG : LOG_NOTICE,
+                         "%s: control process exited, code=%s status=%i", u->meta.id, sigchld_code_to_string(code), status);
                 s->failure = s->failure || !success;
 
                 /* If we are shutting things down anyway we
@@ -2462,7 +2478,7 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
              s->state == SERVICE_RELOAD)) {
 
                 if (parse_pid(e + 8, &pid) < 0)
-                        log_warning("Failed to parse %s", e);
+                        log_warning("Failed to parse notification message %s", e);
                 else {
                         log_debug("%s: got %s", u->meta.id, e);
                         service_set_main_pid(s, pid);
@@ -2718,6 +2734,17 @@ int service_set_socket_fd(Service *s, int fd, Socket *sock) {
         return 0;
 }
 
+static void service_reset_maintenance(Unit *u) {
+        Service *s = SERVICE(u);
+
+        assert(s);
+
+        if (s->state == SERVICE_MAINTENANCE)
+                service_set_state(s, SERVICE_DEAD);
+
+        s->failure = false;
+}
+
 static const char* const service_state_table[_SERVICE_STATE_MAX] = {
         [SERVICE_DEAD] = "dead",
         [SERVICE_START_PRE] = "start-pre",
@@ -2805,6 +2832,8 @@ const UnitVTable service_vtable = {
         .sigchld_event = service_sigchld_event,
         .timer_event = service_timer_event,
 
+        .reset_maintenance = service_reset_maintenance,
+
         .cgroup_notify_empty = service_cgroup_notify_event,
         .notify_message = service_notify_message,