4

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,

  • Why do you have Before=shutdown.target reboot.target halt.target? This is unnecessary and it might be causing the problem. – Michael Hampton Feb 20 '15 at 21:00
  • Thanks for the idea, but that doesn't help. I tried and I got the exact same problems. – Mariano Martinez Peck Feb 23 '15 at 15:58
-1

Try

[Unit]
Description=My sites
After=NetworkManager.service
Requires=NetworkManager.service

[Service]
Type=oneshot
ExecStart=/bin/bash -c '/etc/xxx/mySites start'
ExecStop=/bin/bash -c '/etc/xxx/mySites stop'
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.