I have a systemd script which is as follows:
[Unit]
Description=My sites
Before=shutdown.target reboot.target halt.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c '/etc/xxx/mySites start'
ExecStop=/bin/bash -c '/etc/xxx/mySites stop'
KillMode=none
SendSIGKILL=no
TimeoutStopUSec=5min
TimeoutSec=5min
TimeoutStopSec=5min
[Install]
WantedBy=multi-user.target
Now...if I try to execute sudo systemctl start mySites.service
it seems the service is run and all my stuff is started correctly. If I do a stop
it works too. Then, at OS boot, it also starts correct. The problem is on the OS shutdown. I am rebooting it and it seems like if the ExecStop
WAS called too...but too late... I see in the logs that my processes all received a kill as I can see in my logs:
signal 15, SIGTERM, received from process 1 userId 0
si_code: 0, SI_USER, signal from kill(2), sigsend(2), raise(3C) or abort(3C)
si_signo 15 si_errno 0
So..ExecStop
seems to be being called too late because someone already killed the processes I originally started. Yet, I am already setting Before=shutdown.target reboot.target halt.target
.
I think the problem might be that my ExecStop
may take longer than the default timeout, and hence systemd ends up sending SIGTERM. Now... I have set KillMode=none
, SendSIKKILL=no
and even all the possible timeouts to 5 minutes to TimeoutStopUSec
, TimeoutSec
and TimeoutStopSec
(for sure my ExecStop
takes less than 5 minutes).
Still no luck.
Any idea how can I fix this? I am running CentOS 7.
Thanks in advance,