return true;
}
else {
- return start_ps_process(exec_arg_parts, onstart_flags.runs_on_console);
+ return start_ps_process(exec_arg_parts, onstart_flags.starts_on_console);
}
}
restart_timer.add_timer(eventLoop);
}
+void base_process_service::do_restart() noexcept
+{
+ restarting = false;
+
+ // We may be STARTING (regular restart) or STARTED ("smooth recovery"). This affects whether
+ // the process should be granted access to the console:
+ bool on_console = service_state == ServiceState::STARTING
+ ? onstart_flags.starts_on_console : onstart_flags.runs_on_console;
+
+ if (! start_ps_process(exec_arg_parts, on_console)) {
+
+ if (service_state == ServiceState::STARTING) {
+ failed_to_start();
+ }
+ else {
+ desired_state = ServiceState::STOPPED;
+ forceStop();
+ }
+ service_set->processQueues();
+ }
+}
+
void base_process_service::restart_ps_process() noexcept
{
timespec current_time;
if (tdiff_s > 0 || tdiff_ns > 200000000) {
// > 200ms
- restarting = false;
- if (! start_ps_process(exec_arg_parts, onstart_flags.runs_on_console)) {
- // TODO handle appropriately; mark service stopped.
- }
+ do_restart();
}
else {
timespec timeout;
dasynq::rearm process_restart_timer::timer_expiry(EventLoop_t &, int expiry_count)
{
- return service->restart_timer_expired();
-}
-
-dasynq::rearm base_process_service::restart_timer_expired() noexcept
-{
- // begin starting process:
- if (! start_ps_process(exec_arg_parts, onstart_flags.runs_on_console)) {
- // TODO handle appropriately; mark service stopped.
- }
+ service->do_restart();
return dasynq::rearm::DISARM;
}
friend class ServiceIoWatcher;
friend class process_restart_timer;
+ private:
+ // Re-launch process
+ void do_restart() noexcept;
+
protected:
ServiceChildWatcher child_listener;
ServiceIoWatcher child_status_listener;
process_restart_timer restart_timer;
timespec last_start_time;
- // start the process, return true on success
+ // Start the process, return true on success
virtual bool start_ps_process() noexcept;
bool start_ps_process(const std::vector<const char *> &args, bool on_console) noexcept;
- // restart the process (due to start failure or unexpected termination). Restarts will be
+ // Restart the process (due to start failure or unexpected termination). Restarts will be
// rate-limited.
void restart_ps_process() noexcept;
virtual void all_deps_stopped() noexcept;
virtual void handle_exit_status(int exit_status) noexcept = 0;
- dasynq::rearm restart_timer_expired() noexcept;
public:
base_process_service(ServiceSet *sset, string name, ServiceType service_type, string &&command,