You are helping the user identify and diagnose failed systemd units (services, mounts, timers, etc.).
Diagnose failed systemd units by listing failures, analyzing logs and dependencies, and attempting restarts. Use when services won't start or system shows errors.
/plugin marketplace add danielrosehill/linux-desktop-plugin/plugin install lan-manager@danielrosehillYou are helping the user identify and diagnose failed systemd units (services, mounts, timers, etc.).
List all failed units:
# Show failed units
systemctl --failed
# More detailed output
systemctl --failed --all
# Include user units
systemctl --user --failed
Get detailed status of failed units:
# For each failed unit, get details
for unit in $(systemctl --failed --no-legend | awk '{print $1}'); do
echo "=== $unit ==="
systemctl status "$unit" --no-pager -l
echo ""
done
Check recent failures:
# Units that failed in last boot
systemctl list-units --failed --state=failed
# Check boot log for failures
journalctl -b -p err | grep -i "failed"
Analyze specific failed unit:
# Status with full output
systemctl status UNIT_NAME -l --no-pager
# Recent logs for the unit
journalctl -u UNIT_NAME -n 50 --no-pager
# Logs from current boot
journalctl -b -u UNIT_NAME --no-pager
# All logs for the unit
journalctl -u UNIT_NAME --since "24 hours ago" --no-pager
Check unit dependencies:
# What this unit depends on
systemctl list-dependencies UNIT_NAME
# What depends on this unit
systemctl list-dependencies --reverse UNIT_NAME
# Check if dependencies failed
systemctl list-dependencies UNIT_NAME --all | while read dep; do
systemctl is-failed "$dep" 2>/dev/null | grep -q "^failed" && echo "FAILED: $dep"
done
Common failure patterns:
# Mount failures
systemctl --failed | grep ".mount"
# Service failures
systemctl --failed | grep ".service"
# Timer failures
systemctl --failed | grep ".timer"
# Network-related failures
systemctl --failed | grep -E "network|dhcp|dns"
Attempt to diagnose failure reason:
# Exit code and signal
systemctl show UNIT_NAME | grep -E "ExecMainStatus|ExecMainCode|Result"
# Unit file location and settings
systemctl cat UNIT_NAME
# Check if unit file exists and is valid
systemctl show UNIT_NAME -p LoadState,ActiveState,SubState,Result
Try to restart failed units:
# Ask user if they want to attempt restart
# List failed units
failed_units=$(systemctl --failed --no-legend | awk '{print $1}')
# For each unit, ask to restart
for unit in $failed_units; do
echo "Attempting to restart: $unit"
sudo systemctl restart "$unit"
systemctl is-active --quiet "$unit" && echo "✓ $unit restarted successfully" || echo "✗ $unit restart failed"
done
Check for masked units:
# List masked units
systemctl list-unit-files | grep masked
# Check if failed unit is masked
systemctl is-enabled UNIT_NAME
Generate failure report:
cat > /tmp/failed-units-report.txt << EOF
Failed Units Report - $(date)
======================================
Failed Units Summary:
$(systemctl --failed --no-pager)
Detailed Status:
EOF
for unit in $(systemctl --failed --no-legend | awk '{print $1}'); do
echo "" >> /tmp/failed-units-report.txt
echo "=== $unit ===" >> /tmp/failed-units-report.txt
systemctl status "$unit" --no-pager -l >> /tmp/failed-units-report.txt 2>&1
echo "" >> /tmp/failed-units-report.txt
echo "Recent Logs:" >> /tmp/failed-units-report.txt
journalctl -u "$unit" -n 20 --no-pager >> /tmp/failed-units-report.txt 2>&1
echo "" >> /tmp/failed-units-report.txt
done
cat /tmp/failed-units-report.txt
Provide:
NetworkManager-wait-online.service:
sudo systemctl disable NetworkManager-wait-online.serviceModemManager.service:
sudo systemctl disable ModemManager.servicebluetooth.service:
journalctl -u bluetooth | grep -i firmwaresudo systemctl restart bluetoothsystemd-resolved.service:
/etc/systemd/resolved.confresolvectl statusMount units (*.mount):
cat /etc/fstablsblkUser services:
journalctl --user -u UNIT_NAMEloginctl enable-linger USER# Reset failed state
sudo systemctl reset-failed
# Disable permanently failed units (ask first!)
sudo systemctl disable UNIT_NAME
# Mask unit to prevent activation
sudo systemctl mask UNIT_NAME
# Unmask unit
sudo systemctl unmask UNIT_NAME
# Reload systemd configuration
sudo systemctl daemon-reload
systemctl reset-failed to clear failed state after fixing