Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

333
Visualizações
systemd: SIGTERM immediately after start

I am trying systemd for the first time. I want to start a process at system bootup. And I have a problem in getting it up and running.

systemd should run a script (start.sh). This script starts a processes (lets call it P) in the background and exits with code 0. P keeps running forever till a signal happends.

If I run start.sh manually all is ok.

If I let it start by systemd P gets immediately after the start a SIGTERM and terminates.

So it get started but what about the signal?? It terminates P and I am not sure whats its origin and the reason for it.

Maybe my unit is wrong but I have no idea how to set it for my needs. I tried service-type simple, idle and oneshot.

Thanks for help! Chris

Here is my unit.

[Unit]
Description=Test
After=sshd.service

[Service]
Type=oneshot
ExecStart=/home/max/start.sh start
Restart=no
User=root
SuccessExitStatus=0

[Install]
WantedBy=multi-user.target

Thats the status.

Loaded: loaded (/etc/systemd/system/test.service; enabled)
Active: inactive (dead) since Die 2016-02-23 20:56:59 CET; 20min ago
Process: 1046 ExecStart=/home/max/test.sh start (code=exited, status=0/SUCCESS)
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

When start.sh finishes, systemd kills everything in the same cgroup as start.sh

Your options are:

  • setting KillMode in the Unit section to process (the default is control-group). That will cause systemd to only kill the process which it directly fired.

  • to not make start.sh start something in the background and exit but to execute it right there in the foreground

I think in your situation option 2 is viable and more straightforward.

Source: https://unix.stackexchange.com/a/231201/45329

over 4 years ago · Santiago Trujillo Relatório

0

Although changing the KillMode to process like below will work in your situation, it is not the recommended solution.

[Service]
KillMode=process
...

The problem with KillMode set to process is that systemd loses control over all the children of the process it started. That means, if anything happens and one of your processes does not die for some reason, it will continue to linger around.

A better solution in your situation would be to create all the processes, keep their pid and then wait on them.

The wait command that you use in your shell script may vary depending on which shell you are using (the link I proposed is for bash). Having the shell script wait for all the children is in effect the same as starting one child, which does not get detached, in the foreground.

So something like this, more or less:

#!/bin/bash

# Start your various processes
process1 &
PROCESS1_PID=$!
process2 &
PROCESS2_PID=$!
process3 &
PROCESS3_PID=$!

# Wait on your processes
wait $PROCESS1_PID $PROCESS2_PID $PROCESS3_PID

# OR, if I'm correct, bash also allows you to wait on all children
# with just a plain wait like so:
wait

# reach here only after children 1, 2, and 3 died
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda