systemd stop 命令的实际工作原理 [英] How systemd stop command actually works

查看:134
本文介绍了systemd stop 命令的实际工作原理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 systemd 服务,该服务在启动"进程时调用该进程(例如 $systemctl start test.service).根据设计,进程永远处于循环中,我们可以使用ps"命令查看进程存在.我们还看到该进程被 systemctl stop 命令杀死(如预期).但是我们的要求是,我们希望在进程被杀死之前从进程内部执行一些安全的关闭操作.但我不确定如何从进程中检测 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.

systemctl stop test.service 命令是否发送 SIGKILL 或 SIGTERM 信号来终止进程?如何从进程中检测 systemctl stop 操作?

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?

推荐答案

默认情况下,发送 SIGTERM,然后等待 90 秒,然后是 SIGKILL.

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

使用 systemd 杀死进程是非常可定制的并且文档齐全.

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

我建议阅读所有 man systemd.kill 作为以及阅读ExecStop= in man systemd.service.

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.

这篇关于systemd stop 命令的实际工作原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆