Home

ExecStop

ExecStop is a directive used in systemd unit files to specify commands that should be executed when a unit is stopped. It provides a hook for graceful shutdown and resource cleanup for services and other units managed by systemd.

In a unit file, ExecStop takes a command and its arguments. Multiple ExecStop lines may be declared,

ExecStop work is complemented by ExecStopPost, which runs after the main stop sequence has completed to perform

Configuration notes and behavior: ExecStop commands can rely on environment variables such as $MAINPID. They are

Example:

[Service]

ExecStart=/usr/bin/mydaemon

ExecStop=/usr/bin/mydaemon --shutdown

ExecStopPost=/usr/bin/cleanup-sockets

ExecStop is a standard mechanism for implementing graceful shutdown logic within systemd-managed services.

and
systemd
will
run
them
in
the
order
they
appear
as
part
of
the
stop
action
(for
example,
when
issuing
systemctl
stop
or
during
system
shutdown).
These
commands
are
intended
to
perform
tasks
such
as
terminating
external
processes,
closing
network
connections,
releasing
resources,
or
notifying
other
components
that
the
service
is
stopping.
additional
cleanup
tasks
that
should
occur
after
termination.
Together,
ExecStop
and
ExecStopPost
provide
a
two-stage
shutdown
approach:
an
immediate
stop
sequence,
followed
by
post-stop
cleanup.
subject
to
the
unit’s
stop-related
timing,
including
TimeoutStopSec
and
KillMode,
which
influence
how
long
the
stop
can
take
and
how
processes
are
terminated.
If
an
ExecStop
command
exits
with
a
non-zero
status,
the
outcome
can
affect
the
overall
stop
action
depending
on
unit
configuration
and
policy.