mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:37:35 +00:00
SystemServer: Limit service restarts
SystemServer will now track the number of restart attempts and the run time of a service, and will also pay attention to its exit code. If a service exits unsuccessfully and too quickly (in less than a second), SystemServer will only attempt to restart it twice. This means that if WindowServer crashes on startup, we will now see just a few copies of the crash instead of the quickly scrolling log flashing with colors :^)
This commit is contained in:
parent
960df8a62a
commit
6bda3bd8da
2 changed files with 33 additions and 4 deletions
|
@ -179,6 +179,7 @@ void Service::spawn()
|
|||
{
|
||||
dbg() << "Spawning " << name();
|
||||
|
||||
m_run_timer.start();
|
||||
m_pid = fork();
|
||||
|
||||
if (m_pid < 0) {
|
||||
|
@ -256,15 +257,34 @@ void Service::spawn()
|
|||
void Service::did_exit(int exit_code)
|
||||
{
|
||||
ASSERT(m_pid > 0);
|
||||
(void)exit_code;
|
||||
|
||||
dbg() << "Service " << name() << " has exited";
|
||||
dbg() << "Service " << name() << " has exited with exit code " << exit_code;
|
||||
|
||||
s_service_map.remove(m_pid);
|
||||
m_pid = -1;
|
||||
|
||||
if (m_keep_alive)
|
||||
activate();
|
||||
if (!m_keep_alive)
|
||||
return;
|
||||
|
||||
int run_time_in_msec = m_run_timer.elapsed();
|
||||
bool exited_successfully = exit_code == 0;
|
||||
|
||||
if (!exited_successfully && run_time_in_msec < 1000) {
|
||||
switch (m_restart_attempts) {
|
||||
case 0:
|
||||
dbg() << "Trying again";
|
||||
break;
|
||||
case 1:
|
||||
dbg() << "Third time's a charm?";
|
||||
break;
|
||||
default:
|
||||
dbg() << "Giving up on " << name() << ". Good luck!";
|
||||
return;
|
||||
}
|
||||
m_restart_attempts++;
|
||||
}
|
||||
|
||||
activate();
|
||||
}
|
||||
|
||||
Service::Service(const Core::ConfigFile& config, const StringView& name)
|
||||
|
@ -330,4 +350,6 @@ void Service::save_to(JsonObject& json)
|
|||
json.set("pid", m_pid);
|
||||
else
|
||||
json.set("pid", nullptr);
|
||||
|
||||
json.set("restart_attempts", m_restart_attempts);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue