Use the start queue instead of starting services immediately.
authorDavin McCall <davmac@davmac.org>
Thu, 16 Jun 2016 07:26:09 +0000 (08:26 +0100)
committerDavin McCall <davmac@davmac.org>
Thu, 16 Jun 2016 07:26:09 +0000 (08:26 +0100)
src/service.cc
src/service.h

index a7799c6d85e3eba643276af71b5d1fef61d958c1..746a3b625dd99edf871b53d38d8d7ec719e9daf4 100644 (file)
@@ -51,6 +51,7 @@ void ServiceSet::startService(const char *name)
     ServiceRecord *record = loadServiceRecord(name);
     
     record->start();
+    processQueues(true);
 }
 
 void ServiceSet::stopService(const std::string & name) noexcept
@@ -85,7 +86,7 @@ void ServiceRecord::stopped() noexcept
     
     if (will_restart) {
         // Desired state is "started".
-        do_start();
+        service_set->addToStartQueue(this);
     }
     else {
         if (socket_fd != -1) {
@@ -326,7 +327,7 @@ void ServiceRecord::start(bool activate) noexcept
     }
 
     desired_state = ServiceState::STARTED;
-    do_start();
+    service_set->addToStartQueue(this);
 }
 
 void ServiceRecord::do_start() noexcept
@@ -898,12 +899,14 @@ void ServiceRecord::unpin() noexcept
         pinned_started = false;
         if (desired_state == ServiceState::STOPPED) {
             do_stop();
+            service_set->processQueues(false);
         }
     }
     if (pinned_stopped) {
         pinned_stopped = false;
         if (desired_state == ServiceState::STARTED) {
             do_start();
+            service_set->processQueues(true);
         }
     }
 }
index 8b93080ccb98450969686a1776e5a2ca5d6c910a..7c4ca9032aa046eeddcf51dfc4af114f2659cfae 100644 (file)
@@ -729,6 +729,7 @@ class ServiceSet
             (*i)->stop(false);
             (*i)->unpin();
         }
+        processQueues(false);
     }
     
     void set_auto_restart(bool restart) noexcept