'\" 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