chiark / gitweb /
service: make start jobs wait, not fail, when an automatic restart is queued
[elogind.git] / src / core / service.c
index 2be6ee5d99a992459cfdc0478d5add4c73928fb7..cf480ab979d3be55cea1a0e7b880a2c936b140a3 100644 (file)
@@ -1282,6 +1282,10 @@ static int service_load(Unit *u) {
                 if (UNIT(s)->default_dependencies)
                         if ((r = service_add_default_dependencies(s)) < 0)
                                 return r;
+
+                r = unit_patch_working_directory(UNIT(s), &s->exec_context);
+                if (r < 0)
+                        return r;
         }
 
         return service_verify(s);
@@ -2254,10 +2258,12 @@ static void service_enter_restart(Service *s) {
         assert(s);
         dbus_error_init(&error);
 
-        if (UNIT(s)->job) {
-                log_info("Job pending for unit, delaying automatic restart.");
+        if (UNIT(s)->job && UNIT(s)->job->type == JOB_STOP) {
+                /* Don't restart things if we are going down anyway */
+                log_info("Stop job pending for unit, delaying automatic restart.");
 
-                if ((r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch)) < 0)
+                r = unit_watch_timer(UNIT(s), s->restart_usec, &s->timer_watch);
+                if (r < 0)
                         goto fail;
 
                 return;
@@ -2271,6 +2277,10 @@ static void service_enter_restart(Service *s) {
         if (r < 0)
                 goto fail;
 
+        /* Note that we stay in the SERVICE_AUTO_RESTART state here,
+         * it will be canceled as part of the service_stop() call that
+         * is executed as part of JOB_RESTART. */
+
         log_debug("%s scheduled restart job.", UNIT(s)->id);
         return;
 
@@ -2464,12 +2474,12 @@ static int service_start(Unit *u) {
                 return 0;
 
         /* A service that will be restarted must be stopped first to
-         * trigger BindTo and/or OnFailure dependencies. If a user
+         * trigger BindsTo and/or OnFailure dependencies. If a user
          * does not want to wait for the holdoff time to elapse, the
          * service should be manually restarted, not started. */
         if (s->state == SERVICE_AUTO_RESTART) {
                 log_warning("%s automatic restart is pending, must be stopped before issuing start request.", UNIT(s)->id);
-                return -ECANCELED;
+                return -EAGAIN;
         }
 
         assert(s->state == SERVICE_DEAD || s->state == SERVICE_FAILED);