// This may be a "smooth recovery" where we are restarting the process while leaving the
// service in the STARTED state.
if (restarting && service_state == service_state_t::STARTED) {
- //restarting = false;
bool need_stop = false;
if ((did_exit && exit_status.get_exit_status() != 0) || was_signalled) {
need_stop = true;
return;
}
- //restarting = false;
if (service_state == service_state_t::STARTING) {
// POSIX requires that if the process exited clearly with a status code of 0,
// the exit status value will be 0:
force_stop = false;
+ // If we are to re-start, restarting should have been set true and desired_state should be STARTED.
+ // (A restart could be cancelled via a separately issued stop, including via a shutdown).
restarting |= auto_restart;
- bool will_restart = restarting && required_by > 0;
+ bool will_restart = restarting && desired_state == service_state_t::STARTED;
if (restarting && ! will_restart) {
notify_listeners(service_event_t::STARTCANCELLED);
}
bring_down = true;
}
+ // Set desired state to STOPPED, this will be set back to STARTED if there any hard dependents
+ // that want to restart.
desired_state = service_state_t::STOPPED;
if (bring_down && service_state != service_state_t::STOPPED
assert(p.get_state() == service_state_t::STARTED);
assert(event_loop.active_timers.size() == 0);
+ // simulate process terminating, should then be restarted:
base_process_service_test::handle_exit(&p, 0);
sset.process_queues();
assert(p.get_state() == service_state_t::STARTED);
assert(event_loop.active_timers.size() == 0);
+ assert(sset.count_active_services() == 2);
+
+ // Request stop, this time it should not restart:
+ p.stop(true);
+ sset.process_queues();
+ base_process_service_test::handle_exit(&p, 0);
+ sset.process_queues();
+
+ assert(p.get_state() == service_state_t::STOPPED);
+ assert(event_loop.active_timers.size() == 0);
+ assert(sset.count_active_services() == 1);
+
+ // simulate terminate dinit
+ sset.stop_all_services();
+
+ //base_process_service_test::handle_exit(&p, 0);
+ sset.process_queues();
+
+ assert(p.get_state() == service_state_t::STOPPED);
+ assert(event_loop.active_timers.size() == 0);
+ assert(sset.count_active_services() == 0);
+
sset.remove_service(&p);
sset.remove_service(&b);
}
-
// Termination via stop request
void test_term_via_stop()
{