Como o systemd manipula a morte dos filhos de processos gerenciados?
Suponha que systemd lance o daemon foo , que então lança outros três daemons: bar1 , bar2 e bar3 . systemd fará qualquer coisa para foo se bar2 terminar inesperadamente? Pelo que entendi, em Service Management Facility (SMF) no Solaris foo seria eliminado ou reiniciado se você não dissesse startd alterando a propriedade ignore_error . O systemd se comporta de maneira diferente?
Editar # 1:
Eu escrevi um daemon de teste para testar o comportamento de systemd . O daemon é chamado de mother_daemon porque gera filhos.
#include <iostream>
#include <unistd.h>
#include <string>
#include <cstring>
using namespace std;
int main(int argc, char* argv[])
{
cout << "Hi! I'm going to fork and make 5 child processes!" << endl;
for (int i = 0; i < 5; i++)
{
pid_t pid = fork();
if (pid > 0)
{
cout << "I'm the parent process, and i = " << i << endl;
}
if (pid == 0)
{
// The following four lines rename the process to make it easier to keep track of with ps
int argv0size = strlen(argv[0]);
string childThreadName = "mother_daemon child thread PID: ";
childThreadName.append( to_string(::getpid()) );
strncpy(argv[0],childThreadName.c_str(),argv0size + 25);
cout << "I'm a child process, and i = " << i << endl;
pause();
// I don't want each child process spawning its own process
break;
}
}
pause();
return 0;
}
Isso é controlado com uma unidade systemd chamada mother_daemon.service :
[Unit]
Description=Testing how systemd handles the death of the children of a managed process
StopWhenUnneeded=true
[Service]
ExecStart=/home/my_user/test_program/mother_daemon
Restart=always
A unidade mother_daemon.service é controlada pelo mother_daemon.target :
[Unit]
Description=A target that wants mother_daemon.service
Wants=mother_daemon.service
Quando eu executo sudo systemctl start mother_daemon.target (depois de sudo systemctl daemon-reload ) eu posso ver o daemon pai e os cinco daemons filhos.
Matar um dos filhos não tem efeito sobre o pai, mas matar o pai (e, assim, desencadear um reinício) reinicia os filhos.
Parar mother_daemon.target com sudo systemctl stop mother_daemon.target também termina os filhos.
Acho que isso responde à minha pergunta.