Browse Source

Remove start pin if start fails

Davin McCall 3 years ago
parent
commit
e29949b037
2 changed files with 8 additions and 2 deletions
  1. 6 1
      doc/manpages/dinitctl.8.m4
  2. 2 1
      src/service.cc

+ 6 - 1
doc/manpages/dinitctl.8.m4

@@ -89,7 +89,12 @@ be unable to start.
 
 A service that is pinned started cannot be stopped, however its explicit activation can be removed
 (eg via the \fBstop\fR or \fBrelease\fR commands). Once unpinned, a service which is not explicitly
-activated, and which has no active dependents, will automatically stop.
+activated, and which has no active dependents, will automatically stop. If a pinned-started service
+fails to start, the pin is removed.
+
+Note that a pin takes effect while the service is starting/stopping, before it reaches the target
+state. For example, issuing a stop command to a service which is starting and which is pinned
+started will have no effect other than removing explicit activation.
 .TP
 \fB\-\-force\fR
 Stop the service even if it will require stopping other services which depend on the specified service.

+ 2 - 1
src/service.cc

@@ -148,7 +148,7 @@ void service_record::release(bool issue_stop) noexcept
             // If we are stopping but would have restarted, we now need to notify that the restart
             // has been cancelled. Other start-cancelled cases are handled by do_stop() (called
             // below).
-            if (desired_state == service_state_t::STARTED) {
+            if (desired_state == service_state_t::STARTED && !pinned_started) {
                 notify_listeners(service_event_t::STARTCANCELLED);
             }
         }
@@ -466,6 +466,7 @@ void service_record::failed_to_start(bool depfailed, bool immediate_stop) noexce
     start_failed = true;
     log_service_failed(get_name());
     notify_listeners(service_event_t::FAILEDSTART);
+    pinned_started = false;
 
     if (immediate_stop) {
         stopped();