From 71fabf0ddbb1e6ed63239821cff216aaf2f099dc Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Tue, 6 Jun 2017 17:16:39 +0100 Subject: [PATCH] Allow service start to be interrupted when waiting for restart timer. --- src/service.cc | 11 +++++++++++ src/service.h | 24 +++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/service.cc b/src/service.cc index 9685497..8595a33 100644 --- a/src/service.cc +++ b/src/service.cc @@ -1200,6 +1200,7 @@ base_process_service::base_process_service(ServiceSet *sset, string name, Servic void base_process_service::do_restart() noexcept { restarting = false; + waiting_restart_timer = false; // We may be STARTING (regular restart) or STARTED ("smooth recovery"). This affects whether // the process should be granted access to the console: @@ -1269,10 +1270,20 @@ bool base_process_service::restart_ps_process() noexcept else { timespec timeout = diff_time(restart_delay, tdiff); restart_timer.arm_timer_rel(eventLoop, timeout); + waiting_restart_timer = true; } return true; } +void base_process_service::interrupt_start() noexcept +{ + // overridden in subclasses + if (waiting_restart_timer) { + restart_timer.stop_timer(eventLoop); + waiting_restart_timer = false; + } +} + dasynq::rearm process_restart_timer::timer_expiry(EventLoop_t &, int expiry_count) { service->do_restart(); diff --git a/src/service.h b/src/service.h index 852eb32..07f5248 100644 --- a/src/service.h +++ b/src/service.h @@ -343,11 +343,16 @@ class ServiceRecord // Whether a STARTING service can immediately transition to STOPPED (as opposed to // having to wait for it reach STARTED and then go through STOPPING). - bool can_interrupt_start() noexcept + virtual bool can_interrupt_start() noexcept { return waiting_for_deps; } + virtual void interrupt_start() noexcept + { + // overridden in subclasses + } + // Whether a STOPPING service can immediately transition to STARTED. bool can_interrupt_stop() noexcept { @@ -594,17 +599,26 @@ class base_process_service : public ServiceRecord int max_restart_interval_count; timespec restart_delay; + bool waiting_restart_timer = false; + // Start the process, return true on success - virtual bool start_ps_process() noexcept; + virtual bool start_ps_process() noexcept override; bool start_ps_process(const std::vector &args, bool on_console) noexcept; // Restart the process (due to start failure or unexpected termination). Restarts will be // rate-limited. bool restart_ps_process() noexcept; - virtual void all_deps_stopped() noexcept; + virtual void all_deps_stopped() noexcept override; virtual void handle_exit_status(int exit_status) noexcept = 0; + virtual bool can_interrupt_start() noexcept override + { + return waiting_restart_timer || ServiceRecord::can_interrupt_start(); + } + + virtual void interrupt_start() noexcept override; + public: base_process_service(ServiceSet *sset, string name, ServiceType service_type, string &&command, std::list> &command_offsets, @@ -614,13 +628,13 @@ class base_process_service : public ServiceRecord { } - void set_restart_interval(timespec interval, int max_restarts) + void set_restart_interval(timespec interval, int max_restarts) noexcept { restart_interval = interval; max_restart_interval_count = max_restarts; } - void set_restart_delay(timespec delay) + void set_restart_delay(timespec delay) noexcept { restart_delay = delay; } -- 2.25.1