LinuxCommandLibrary

systemd-notify

Communicate service status to systemd

TLDR

Notify systemd that the service has completed its initialization and is fully started. It should be invoked when the service is ready to accept incoming requests

$ systemd-notify --booted
copy

Signal to systemd that the service is ready to handle incoming connections or perform its tasks
$ systemd-notify --ready
copy

Provide a custom status message to systemd (this information is shown by systemctl status)
$ systemd-notify --status "[Add custom status message here...]"
copy

SYNOPSIS

systemd-notify [OPTIONS...]

PARAMETERS

--ready
    Indicates that the service has finished its startup process and is ready to accept connections or perform its main function.

--stopping
    Indicates that the service is gracefully shutting down. This can be used to inform systemd of an impending shutdown.

--status=STRING
    Sends a free-form status message STRING to systemd. This message can be viewed by users via systemctl status.

--pid=PID
    Specifies the process ID PID of the service for which the notification is intended. If omitted, the notification applies to the calling process itself.

-h, --help
    Displays a brief help message describing the command's options and exits.

--version
    Shows the program's version information and exits.

DESCRIPTION

systemd-notify is a command-line utility that allows services to send status information and readiness signals to the systemd init system. This mechanism is crucial for services configured with Type=notify in their unit files, as systemd expects these services to explicitly signal when they have completed their initialization and are ready to operate. By sending a --ready signal, services prevent systemd from marking them as active or starting dependent services prematurely.

Beyond readiness, systemd-notify enables services to send arbitrary status messages using --status="...", which can be viewed via systemctl status, offering valuable insights into the service's current state or progress. It also supports sending watchdog reset signals, vital for maintaining service health and enabling automatic restarts if a service becomes unresponsive. This utility provides a robust and standardized way for applications to interact with systemd's service management capabilities.

CAVEATS

systemd-notify primarily functions for services managed by systemd that are configured with Type=notify or have appropriate NotifyAccess settings in their unit files. Communication relies on the NOTIFY_SOCKET environment variable, which systemd automatically sets for the service processes it manages. If this variable is not set, notifications will fail silently or with an error.

INTEGRATION WITH SERVICE UNITS

This command is indispensable for services whose systemd unit files specify Type=notify. For such services, systemd waits for a --ready signal from the service process before considering the service fully started and proceeding with dependent unit activations, ensuring a robust startup sequence.

WATCHDOG FUNCTIONALITY

systemd-notify can be used to send periodic watchdog 'keep-alive' signals if a service unit is configured with WatchdogSec=. If a service fails to send these signals within the specified timeout, systemd can automatically trigger a restart, significantly improving the resilience and availability of critical services.

HISTORY

systemd-notify was introduced as part of the systemd project, which began development around 2010. It represents a modern approach to service management, providing a more reliable and expressive way for daemonizing services to communicate their operational state to the init system, moving beyond traditional methods like simple PID files and basic exit codes.

SEE ALSO

systemd(1), systemctl(1), systemd.service(5), sd_notify(3)

Copied to clipboard