Add 'dependencyStarted' method instead of directly overloading 'start'
authorDavin McCall <davmac@davmac.org>
Wed, 18 Nov 2015 14:23:35 +0000 (14:23 +0000)
committerDavin McCall <davmac@davmac.org>
Wed, 18 Nov 2015 14:23:35 +0000 (14:23 +0000)
service.cc
service.h

index feb9935d632d3985f38e68d58a82e373f89f3357..3114f7ef608ed79e875009793b96147323eb600d 100644 (file)
@@ -211,6 +211,11 @@ void ServiceRecord::start()
     }
 }
 
+void ServiceRecord::dependencyStarted()
+{
+    start();
+}
+
 void ServiceRecord::started()
 {
     logServiceStarted(service_name);
@@ -229,12 +234,12 @@ void ServiceRecord::started()
         // Start any dependents whose desired state is STARTED:
         for (auto i = dependents.begin(); i != dependents.end(); i++) {
             if ((*i)->desired_state == ServiceState::STARTED) {
-                (*i)->start();
+                (*i)->dependencyStarted();
             }
         }
         for (auto i = soft_dpts.begin(); i != soft_dpts.end(); i++) {
             if ((*i)->getFrom()->desired_state == ServiceState::STARTED) {
-                (*i)->getFrom()->start();
+                (*i)->getFrom()->dependencyStarted();
             }
         }
     }
index 9c3cde47f62d5b217e93419f3fd539231f539b88..deff596ab564425b1c5758e7de710233ef792049 100644 (file)
--- a/service.h
+++ b/service.h
@@ -149,9 +149,6 @@ class ServiceRecord
     ServiceType service_type;  /* ServiceType::DUMMY, PROCESS, SCRIPTED, INTERNAL */
     ServiceState service_state; /* ServiceState::STOPPED, STARTING, STARTED, STOPPING */
     ServiceState desired_state; /* ServiceState::STOPPED / STARTED */
-    bool force_stop; // true if the service must actually stop. This is the
-                     // case if for example the process dies; the service,
-                     // and all its dependencies, MUST be stopped.
 
     string program_name;          /* storage for program/script and arguments */
     const char **exec_arg_parts;  /* pointer to each argument/part of the program_name */
@@ -160,7 +157,8 @@ class ServiceRecord
 
     string logfile; /* log file name, empty string specifies /dev/null */
     bool auto_restart; /* whether to restart this (process) if it dies unexpectedly */
-    
+
+
     typedef std::list<ServiceRecord *> sr_list;
     typedef sr_list::iterator sr_iter;
     
@@ -180,6 +178,11 @@ class ServiceRecord
     
     ServiceSet *service_set; // the set this service belongs to
     
+    // Process services:
+    bool force_stop; // true if the service must actually stop. This is the
+                     // case if for example the process dies; the service,
+                     // and all its dependencies, MUST be stopped.
+
     // Implementation details
     
     pid_t pid;  /* PID of the process. If state is STARTING or STOPPING,
@@ -209,11 +212,14 @@ class ServiceRecord
     // For process services, start the process, return true on success
     bool start_ps_process() noexcept;
     bool start_ps_process(const std::vector<std::string> &args) noexcept;
-   
+
     // Callback from libev when a child process dies
     static void process_child_callback(struct ev_loop *loop, struct ev_child *w,
             int revents);
-    
+
+    // A dependency has reached STARTED state
+    void dependencyStarted();
+
     // A dependent has reached STOPPED state
     void dependentStopped();
 
@@ -228,7 +234,7 @@ class ServiceRecord
     public:
 
     ServiceRecord(ServiceSet *set, string name)
-        : service_state(ServiceState::STOPPED), desired_state(ServiceState::STOPPED), force_stop(false), auto_restart(false)
+        : service_state(ServiceState::STOPPED), desired_state(ServiceState::STOPPED), auto_restart(false), force_stop(false)
     {
         service_set = set;
         service_name = name;
@@ -237,7 +243,7 @@ class ServiceRecord
     
     ServiceRecord(ServiceSet *set, string name, ServiceType service_type, string &&command, std::list<std::pair<unsigned,unsigned>> &command_offsets,
             sr_list * pdepends_on, sr_list * pdepends_soft)
-        : service_state(ServiceState::STOPPED), desired_state(ServiceState::STOPPED), force_stop(false), auto_restart(false)
+        : service_state(ServiceState::STOPPED), desired_state(ServiceState::STOPPED), auto_restart(false), force_stop(false)
     {
         service_set = set;
         service_name = name;