Systemd
provide.foundation.platform.systemd
¶
TODO: Add module docstring.
Functions¶
has_systemd
¶
Check if systemd integration is available.
Returns:
| Type | Description |
|---|---|
bool
|
True if running on Linux and sdnotify is installed, False otherwise |
Example
from provide.foundation.platform import has_systemd if has_systemd(): ... # Use systemd features ... pass
Source code in provide/foundation/platform/systemd.py
notify_error
¶
Notify systemd of an error condition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
errno
|
int
|
Error number (errno value) |
required |
message
|
str | None
|
Optional error message |
None
|
Automatically disabled in test mode (via @skip_in_test_mode decorator).
Returns:
| Type | Description |
|---|---|
bool
|
True if notification sent successfully, False if sdnotify not available |
Example
from provide.foundation.platform import notify_error import errno notify_error(errno.ECONNREFUSED, "Failed to connect to database") True
Source code in provide/foundation/platform/systemd.py
notify_ready
¶
Notify systemd that the service is ready.
This should be called once the service has completed initialization and is ready to handle requests. For Type=notify services, systemd waits for this notification before considering the service started.
Automatically disabled in test mode (via @skip_in_test_mode decorator).
Returns:
| Type | Description |
|---|---|
bool
|
True if notification sent successfully, False if sdnotify not available |
bool
|
or running in test mode |
Example
from provide.foundation.platform import notify_ready
After service initialization¶
notify_ready() True
Source code in provide/foundation/platform/systemd.py
notify_reloading
¶
Notify systemd that the service is reloading configuration.
Call this at the beginning of configuration reload, and call notify_ready() when reload is complete.
Automatically disabled in test mode (via @skip_in_test_mode decorator).
Returns:
| Type | Description |
|---|---|
bool
|
True if notification sent successfully, False if sdnotify not available |
Example
from provide.foundation.platform import notify_reloading, notify_ready notify_reloading() True
Reload configuration¶
notify_ready() True
Source code in provide/foundation/platform/systemd.py
notify_status
¶
Send status text to systemd.
The status will be visible in systemctl status output.
Automatically disabled in test mode (via @skip_in_test_mode decorator).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
Status message to send to systemd |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if notification sent successfully, False if sdnotify not available |
Example
from provide.foundation.platform import notify_status notify_status("Processing requests: 42 active connections") True
Source code in provide/foundation/platform/systemd.py
notify_stopping
¶
Notify systemd that the service is stopping.
Call this at the beginning of graceful shutdown.
Automatically disabled in test mode (via @skip_in_test_mode decorator).
Returns:
| Type | Description |
|---|---|
bool
|
True if notification sent successfully, False if sdnotify not available |
Example
from provide.foundation.platform import notify_stopping
At shutdown¶
notify_stopping() True
Perform cleanup¶
Exit¶
Source code in provide/foundation/platform/systemd.py
notify_watchdog
¶
Send watchdog keepalive to systemd.
If WatchdogSec is configured in the systemd service unit, the service must call this periodically to prevent systemd from considering it hung and restarting it.
Automatically disabled in test mode (via @skip_in_test_mode decorator).
Returns:
| Type | Description |
|---|---|
bool
|
True if notification sent successfully, False if sdnotify not available |
Example
from provide.foundation.platform import notify_watchdog import asyncio async def watchdog_loop(): ... while True: ... await asyncio.sleep(10) # Must be < WatchdogSec ... notify_watchdog()