Restore "restart" flag functionality. Services no longer auto-restart
authorDavin McCall <davmac@davmac.org>
Mon, 11 Jan 2016 22:21:16 +0000 (22:21 +0000)
committerDavin McCall <davmac@davmac.org>
Mon, 11 Jan 2016 22:29:42 +0000 (22:29 +0000)
just because they are active (required) - they now only do so if
the auto-restart flag has been set for the service.

src/service.cc
src/service.h

index ecf9e091048dc3f57e28a6ddbc25f054b45511dc..4be3c52b61542c35fabca8015d68dba571beb457 100644 (file)
@@ -84,7 +84,10 @@ void ServiceRecord::stopped() noexcept
             socket_fd = -1;
         }
         
-        release_dependencies();
+        if (required_by == 0) {
+            // Service is now completely inactive.
+            release_dependencies();
+        }
     }
 }
 
@@ -110,6 +113,14 @@ void ServiceRecord::process_child_callback(struct ev_loop *loop, ev_child *w, in
     sr->handle_exit_status();
 }
 
+bool ServiceRecord::do_auto_restart() noexcept
+{
+    if (auto_restart) {
+        return service_set->get_auto_restart();
+    }
+    return false;
+}
+
 void ServiceRecord::handle_exit_status() noexcept
 {
     if (exit_status != 0 && service_state != ServiceState::STOPPING) {
@@ -133,6 +144,7 @@ void ServiceRecord::handle_exit_status() noexcept
         }
         
         if (need_stop) {
+            if (! do_auto_restart()) desired_state = ServiceState::STOPPED;
             do_stop();
         }
         
@@ -163,6 +175,7 @@ void ServiceRecord::handle_exit_status() noexcept
             return;
         }
         else {
+            if (! do_auto_restart()) desired_state = ServiceState::STOPPED;
             forceStop();
         }
     }
@@ -243,7 +256,8 @@ void ServiceRecord::require() noexcept
             to->require();
         }
         
-        if (service_state != ServiceState::STOPPED) {
+        if (service_state == ServiceState::STOPPED) {
+            // (In any other state, the service is already considered active.)
             service_set->service_active(this);
         }
     }
@@ -712,6 +726,8 @@ void ServiceRecord::stop() noexcept
 {
     if (desired_state == ServiceState::STOPPED && service_state != ServiceState::STARTED) return;
     
+    desired_state = ServiceState::STOPPED;
+    
     if (start_explicit) {
         start_explicit = false;
         release();
index f8bbdebf42f6bd10ad2d72a53bf4733b93aacd1f..3c527b69027e2c529b08a82ff16f38cbca9bb794 100644 (file)
@@ -325,6 +325,8 @@ class ServiceRecord
     // Release console (console must be currently held by this service)
     void releaseConsole() noexcept;
     
+    bool do_auto_restart() noexcept;
+    
     public:
 
     ServiceRecord(ServiceSet *set, string name)