other languages
SYSTEMD-NOTIFY(1) | systemd-notify | SYSTEMD-NOTIFY(1) |
NAME¶
systemd-notify - 向 systemd 報告服務狀態的變化SYNOPSIS¶
systemd-notify [OPTIONS...] [VARIABLE=VALUE...]
描述¶
systemd-notify 可用於 在守護進程腳本中向 systemd 報告進程狀態的變化。 可用於發送任意信息, 其中最重要的是 報告"啓動已完成"的消息。此工具基本上就是對 sd_notify() 的簡單包裝, 以便於在腳本中使用。詳見 sd_notify(3) 手冊。
注意,在報告狀態更新的同時, 還可以傳遞一系列環境變量。
注意, 除非在調用此命令的服務單元中設置了 NotifyAccess=all , 否則 systemd 將會拒絕接受狀態更新的消息。
選項¶
能夠識別的命令行選項如下:--ready
向 systemd
報告"啓動已完成"的消息。
這等價於 systemd-notify READY=1 。
詳見 sd_notify(3) 手冊。
--pid=
向 systemd
報告主守護進程的 PID 。
如果 PID 參數被省略,
將使用調用 systemd-notify
的進程的 PID 。 這等價於
systemd-notify MAINPID=$PID 。 詳見
sd_notify(3) 手冊。
--status=
向 systemd
發送一個任意內容的字符串消息。
這等價於 systemd-notify STATUS=... 。
詳見 sd_notify(3) 手冊。
--booted
用於檢查系統的
init 進程是否爲 systemd ,
返回 0 表示系統的 init
進程是 systemd
,返回非零表示其他。
此選項並不發送任何消息,因此與其他選項沒有任何關係。
詳見 sd_booted(3) 手冊。
另一種檢查方法是
systemctl(1) 的 is-system-running 命令。
若返回 "offline"
則表示系統的 init
進程不是 systemd
-h, --help
顯示簡短的幫助信息並退出。
--version
顯示簡短的版本信息並退出。
退出狀態¶
返回值爲 0 表示成功, 非零返回值表示失敗代碼。例子¶
Example 1. 啓動通知與狀態更新一個簡單的守護進程腳本,在創建好通信管道之後, 向 systemd 報告"啓動已完成"的消息。在運行時, 向 systemd 報告更多的狀態消息:
#!/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
參見¶
systemd(1), systemctl(1), systemd.unit(5), sd_notify(3), sd_booted(3)跋¶
本頁面中文版由中文 man 手冊頁計劃提供。翻譯人員:金步國
金步國作品集:https://www.jinbuguo.com
中文 man
手冊頁計劃:../../man-pages-zh/manpages-zh
systemd 231 |