[systemd-devel] a little help with $MAINPID please

Mantas Mikulėnas grawity at gmail.com
Sat Feb 23 10:15:28 PST 2013


On Sat, Feb 23, 2013 at 8:13 PM, Mantas Mikulėnas <grawity at gmail.com> wrote:
> On Sat, Feb 23, 2013 at 8:01 PM, lux-integ <lux-integ at btconnect.com> wrote:
>> b) what are the advantages or disadvantaes of the following line
>> ExecStop=/bin/kill -15 $(/bin/pidof mysqld)
>> over
>> ExecStop=/bin/kill -15 $MAINPID
>
> The former will simply not work, as Exec lines are not run through a
> shell and $() is not interpreted in them. Even if it worked, it would
> be unreliable as there can be more than one mysqld process. (For
> example, on a desktop system, one copy of mysqld can be running as a
> system service, and a second copy – in the user's login session, as
> KDE uses MySQL as a storage backend. In this case, you would simply
> kill the *wrong process*.)
>
> The latter works, but is redundant, since sending SIGTERM is already
> what systemd does by default if ExecStop is not set. (You can change
> the signal by setting KillSignal.)

In addition, systemd kills *all* processes in the cgroup by default,
so you can be sure that you won't have leftover "helper" processes
left (which various services often use). Plain /bin/kill won't
guarantee that.

-- 
Mantas Mikulėnas <grawity at gmail.com>


More information about the systemd-devel mailing list