Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How systemd stop command actually works

Tags:

systemd

I am using a systemd service which calls a process when it's been "started" (e.g.$systemctl start test.service). As per the design, the process stays for ever in a loop, we are able to see process existence using 'ps' command. We have also seen that the process is getting killed (as intended) for systemctl stop command. However our requirement is, we want to do some safe shutdown operations from within the process before it gets killed. But I am not sure how to detect a systemd stop operation from within the process.

Does a systemctl stop test.service command send SIGKILL or SIGTERM signal to kill the process? How can i detect a systemctl stop operation from within a process?

like image 667
user3805417 Avatar asked Mar 23 '17 14:03

user3805417


People also ask

What does systemd stop do?

On the otherhand systemctl stop will stop one or more units specified on the command line. First systemd will run any ExecStop= lines (if any). If any processes remain, handle these using KillMode= rules. After that, it sends SIGTERM (can be changed with KillSignal= ).

What is ExecStart in systemd?

This option is mandatory for services where Type=dbus . ExecStart. The commands and arguments executed when the service starts. ExecStartPre, ExecStartPost. Additional commands that are executed before or after the command in ExecStart .

What is systemd and how it works?

systemd is a software suite that provides an array of system components for Linux operating systems. Its main aim is to unify service configuration and behavior across Linux distributions; Its primary component is a "system and service manager"—an init system used to bootstrap user space and manage user processes.


1 Answers

By default, a SIGTERM is sent, followed by 90 seconds of waiting followed by a SIGKILL.

Killing processes with systemd is very customizable and well-documented.

I recommend reading all of man systemd.kill as well as reading about ExecStop= in man systemd.service.

To respond to those signals, refer to the signal handling documentation for the language you are using.

like image 55
Mark Stosberg Avatar answered Oct 26 '22 09:10

Mark Stosberg