Introduction
Some Linux services are designed to exit after initialization — and that trips up service monitors. If you're watching one of these with a Service monitor in Level, you'll get false alerts. The fix is a script monitor that reads SubState instead of ActifState.
Why Moniteur de services Fire False Alertes
systemd tracks each unit across two status fields: ActifState and SubState. Service monitors check ActifState — values like active, inactive, or failed.
The problem: certain services exit after doing their job and never enter a persistent active state. WireGuard's wg-quick is the most common example. It configures the VPN interface, then exits. systemd records ActifState as inactive (exited). A service monitor sees inactive and fires an alert — even though the VPN is running correctly, the interface is up, and traffic is routing.
SubState tells a more accurate story. For services like wg-quick, a healthy SubState is exited — expected and normal. A SubState of failed would mean something actually went wrong. Checking SubState directly is what lets you tell the difference.
Check SubState with a Script
Use systemctl show to read the SubState for any unit:
systemctl show -p SubState --value <unit_name>
This returns a single string — running, exited, dead, failed, etc. — that you can evaluate in a script monitor.
🖥️ PLATFORM REMARQUE :
Linux: Supported on any distribution using systemd.
Windows / macOS: Nont applicable.
systemctlis Linux-only.
Example: Moniteuring a WireGuard Interface
The script below checks whether wg-quick@wg0 is in the expected exited SubState. Swap in your actual unit name if it's different.
#!/bin/bash
UNIT_NAME="wg-quick@wg0"
STATUS=$(systemctl show -p SubState --value $UNIT_NAME)
if [ "$STATUS" = "exited" ]; then
echo "Service is running correctly."
exit 0
else
echo "ALERT: Service is not running. SubState: $STATUS"
exit 1
fi
The script outputs a readable status string and exits with code 0 (healthy) or 1 (unexpected state). Configurer the script monitor to trigger when output Contains the failure string of "ALERT".
Moniteur configuration:
Field | Value |
Tapez | Run script |
OS | Linux |
Script | Linux - WireGuard SubState Check |
Script output | Contains |
Value |
|
Run frequency | 5 minutes |
Trigger count | 2 |
💡 CONSEIL : Set Trigger count to 2 or higher to avoid alerts from transient states during service restarts or reboots.
Other Unit Tapezs That Exit by Design
wg-quick is the most common case, but any of these can trigger the same false-alert pattern:
Oneshot services — run a task and exit;
SubStatewill beexitedwhen healthyHeurer units — run on a schedule; check
ActifStatefor the timer unit itself, not the service it launchesTapez=forking services — parent process exits after spawning a child; SubState may be
exitedwhile the child runs
For all of these, a script monitor checking SubState against your known-good value is the right approach.
Questions fréquemment posées
My WireGuard service shows as Down in Level but traffic is routing fine. What's happening?
wg-quickexits after setting up the VPN interface — that's normal. The network interface stays active even though the service process exited. A service monitor seesinactiveand fires an alert. Use a script monitor that checksSubState(which returnsexited, the healthy value) instead.How do I know what SubState value to expect when a service is healthy? Run
systemctl show -p SubState --value <unit_name>on a device where the service is working correctly. Whatever it returns is your healthy baseline. Script against that value.Can I check both ActifState and SubState in the same monitor? Oui. Write the script to read both and fail if either is unexpected. This gives you broader coverage — you can catch services that exited unexpectedly (
SubState: failed) separately from services that are simply stopped (ActifState: inactive).Does this work on Linux distributions that don't use systemd? Non.
systemctlrequires systemd. On distributions using SysVinit or Upstart, you'd need different tooling (e.g.,service <name> status). Most actively-maintained Linux distributions ship with systemd.
