From 9c28492911918c8fdd3cdb48bc479f2c4700ce1a Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Mon, 11 Jan 2016 22:21:16 +0000 Subject: [PATCH] Restore "restart" flag functionality. Services no longer auto-restart 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 | 20 ++++++++++++++++++-- src/service.h | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/service.cc b/src/service.cc index ecf9e09..4be3c52 100644 --- a/src/service.cc +++ b/src/service.cc @@ -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(); diff --git a/src/service.h b/src/service.h index f8bbdeb..3c527b6 100644 --- a/src/service.h +++ b/src/service.h @@ -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) -- 2.25.1