'\" t .TH "SYSTEMD\-NOTIFY" "1" "" "systemd 231" "systemd-notify" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" systemd-notify \- 向 systemd 报告服务状态的变化 .SH "SYNOPSIS" .HP \w'\fBsystemd\-notify\ \fR\fB[OPTIONS...]\fR\fB\ \fR\fB[VARIABLE=VALUE...]\fR\ 'u \fBsystemd\-notify \fR\fB[OPTIONS...]\fR\fB \fR\fB[VARIABLE=VALUE...]\fR .SH "描述" .PP \fBsystemd\-notify\fR 可用于 在守护进程脚本中向 systemd 报告进程状态的变化。 可用于发送任意信息, 其中最重要的是 报告"启动已完成"的消息。 .PP 此工具基本上就是对 \fBsd_notify()\fR 的简单包装, 以便于在脚本中使用。详见 \fBsd_notify\fR(3) 手册。 .PP 注意,在报告状态更新的同时, 还可以传递一系列环境变量。 .PP 注意, 除非在调用此命令的服务单元中设置了 \fINotifyAccess=all\fR , 否则 systemd 将会拒绝接受状态更新的消息。 .SH "选项" .PP 能够识别的命令行选项如下: .PP \fB\-\-ready\fR .RS 4 向 systemd 报告"启动已完成"的消息。 这等价于 \fBsystemd\-notify READY=1\fR 。 详见 \fBsd_notify\fR(3) 手册。 .RE .PP \fB\-\-pid=\fR .RS 4 向 systemd 报告主守护进程的 PID 。 如果 PID 参数被省略, 将使用调用 \fBsystemd\-notify\fR 的进程的 PID 。 这等价于 \fBsystemd\-notify MAINPID=$PID\fR 。 详见 \fBsd_notify\fR(3) 手册。 .RE .PP \fB\-\-status=\fR .RS 4 向 systemd 发送一个任意内容的字符串消息。 这等价于 \fBsystemd\-notify STATUS=\&.\&.\&.\fR 。 详见 \fBsd_notify\fR(3) 手册。 .RE .PP \fB\-\-booted\fR .RS 4 用于检查系统的 init 进程是否为 systemd , 返回 0 表示系统的 init 进程是 systemd ,返回非零表示其他。 此选项并不发送任何消息,因此与其他选项没有任何关系。 详见 \fBsd_booted\fR(3) 手册。 另一种检查方法是 \fBsystemctl\fR(1) 的 \fBis\-system\-running\fR 命令。 若返回 "offline" 则表示系统的 init 进程不是 systemd .RE .PP \fB\-h\fR, \fB\-\-help\fR .RS 4 显示简短的帮助信息并退出。 .RE .PP \fB\-\-version\fR .RS 4 显示简短的版本信息并退出。 .RE .SH "退出状态" .PP 返回值为 0 表示成功, 非零返回值表示失败代码。 .SH "例子" .PP \fBExample\ \&1.\ \&启动通知与状态更新\fR .PP 一个简单的守护进程脚本,在创建好通信管道之后, 向 systemd 报告"启动已完成"的消息。在运行时, 向 systemd 报告更多的状态消息: .sp .if n \{\ .RS 4 .\} .nf #!/bin/bash mkfifo /tmp/waldo systemd\-notify \-\-ready \-\-status="Waiting for data\&.\&.\&." while : ; do read a < /tmp/waldo systemd\-notify \-\-status="Processing $a" # Do something with $a \&.\&.\&. systemd\-notify \-\-status="Waiting for data\&.\&.\&." done .fi .if n \{\ .RE .\} .SH "参见" .PP \fBsystemd\fR(1), \fBsystemctl\fR(1), \fBsystemd.unit\fR(5), \fBsd_notify\fR(3), \fBsd_booted\fR(3) .SH "跋" .br 本页面中文版由中文 man 手册页计划提供。 .PP 翻译人员:金步国 .br 金步国作品集:http://www.jinbuguo.com .br .br 中文 man 手册页计划:\fBhttps://github.com/man-pages-zh/manpages-zh\fR