【发布时间】:2019-04-18 23:48:59
【问题描述】:
我无法理解 Systemd 的通知模型和几个工作流程。 Systemd 通知使用sd_notify (3) 接口发生。 sd_notify (3) 接口为守护进程提供了一种告诉 systemd 其状态的方法:
#include <systemd/sd-daemon.h>
int sd_notify(int unset_environment,
const char *state);
int sd_notifyf(int unset_environment,
const char *format,
...);
...
如果我正确解析了手册页,则守护程序应在启动并准备好处理数据后调用sd_notify(0, "READY=1\n");。当它停止时,它应该调用sd_notify(0, "STOPPING=1\n");。
这是我遇到问题的工作流程之一。我看不到 Systemd 如何将消息传递给守护进程,说 “更新您的状态”,因此可以通过 systemctl status 向用户报告。
systemctl status mydaemon.service
我遇到问题的另一个工作流程是关机。我看不到 Systemd 如何将关闭消息传递给守护进程。
在这两种情况下,我都觉得我的可执行文件应该导出一个函数,而 Systemd 应该为查询和消息调用它。
Systemd 如何告诉守护进程报告其状态或关闭?
【问题讨论】:
标签: c daemon systemd status shutdown