SCIENTIFIC-LINUX-USERS Archives

October 2017

SCIENTIFIC-LINUX-USERS@LISTSERV.FNAL.GOV

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Vladimir Mosgalin <[log in to unmask]>
Reply To:
Vladimir Mosgalin <[log in to unmask]>
Date:
Mon, 30 Oct 2017 16:20:20 +0300
Content-Type:
text/plain
Parts/Attachments:
text/plain (52 lines)
Hi ToddAndMargo!

 On 2017.10.27 at 16:57:38 -0700, ToddAndMargo wrote next:

> I was wondering why one would go through all the effort
> to do a "ExecStop" in systemd if shutdown was going to send
> SIGTERM to everyone anyway.  Well because the process might
> not have long enough to shutdown before the SIGKILL or have
> all its sub process complete properly either.

There are lots of reasons to have ExecStop (especially for databases).
First is handling the case when database can't accept SIGTERM correctly
and needs specific command to shutdown instead (e.g. Oracle DB). Second
is need to do some pre/post shutdown cleanup, e.g. you want to send some
notification to someone else before shutdown. Third is manual picking of
process to terminate, systemd can either kill very first process with
SIGTERM or kill all, but there are cases when you need to kill something
else. For example, this is tree of running processes:

(1) wrapper
    | 
    (2) control manager
        |
        (3) child 1
        (4) child 2
        (5) child 3

systemd can kill either (1) or (1-5) depending on settings, but killing
(1) is useless and killing (3-5) directly might harm the service state,
the only way to correctly shutdown is to send signal to (2) (or 1 and 2
at once).  Here you'll need ExecStop again.

I'd say that the only annoyance here is that ExecStop must be
synchronous, it must actually wait till everything shutdowns before
returning, otherwise systemd will treat it as failed shutdown attempt
and kill the service remains right after ExecStop returns. So if you're
going to stop by sending SIGTERM to some specific process, you need a
wrapper script for ExecStop which waits till everything has shutdown
properly. You can't use one that calls shutdown in background and
returns without waiting.


Anyhow, just like ExecStop allows these kinds of customizations, you can
also define "TimeoutStopSec" parameter (e.g. TimeoutStopSec=5min) and
systemd will wait that time either after sending SIGTERM (if there is no
ExecStop) or after ExecStop and before sending SIGKILL (ExecStop command
will be aborted in that case when the time has ran out).

-- 

Vladimir

ATOM RSS1 RSS2