-
-
Notifications
You must be signed in to change notification settings - Fork 2
Systemctl Troubleshooting
- 📝 What is systemctl?
- ⚡ Basic Commands
- 🔍 Checking Service Status
- :desktop: Listing Services
- 🔧 Controlling Services
- Starting a Service
- Stopping a Service
- Restarting a Service
- Reloading a Service
- Try-Restart (Restart Only If Running)
- Reload-or-Restart
- Enable Service to Start at Boot
- Disable Service from Starting at Boot
- Enable and Start Together
- Disable and Stop Together
- Masking a Service
- Scenario 1: Service Won't Start
- Scenario 2: Service Keeps Crashing
- Scenario 3: Service Not Starting at Boot
- Scenario 4: Finding What's Using a Port
- Scenario 5: Service Takes Too Long to Start
- Scenario 6: Understanding Service Dependencies
- Status Commands
- Control Commands
- Enable/Disable Commands
- Listing Commands
- Information Commands
- Maintenance Commands
-
systemctlis the command-line tool for managing systemd services and units - It allows you to control, monitor, and troubleshoot system services
- systemd is the system and service manager used by most modern Linux distributions
- Services are called "units" in systemd terminology
What systemctl can do:
- Start, stop, restart, and reload services
- Check service status and health
- Enable/disable services to start at boot
- View service logs
- Check service dependencies
- Troubleshoot failed services
systemctl --helpShows all available systemctl commands and options.
systemctl statusShows the overall system status, including:
- System state (running, degraded, etc.)
- Number of loaded units
- Number of failed units
- System uptime
- systemd version
Example output:
● fedora
State: running
Units: 746 loaded (incl. loaded aliases)
Jobs: 0 queued
Failed: 0 units
Since: Thu 2025-11-13 03:33:58 AST; 11h ago
systemd: 258.1-1.fc43
systemctl status servicenameWhat this does:
- Shows detailed information about a service
- Displays current state (active/inactive, running/stopped)
- Shows recent log entries
- Indicates if the service is enabled to start at boot
Common service names:
-
sshd- SSH server -
nginx- Nginx web server -
httpdorapache2- Apache web server -
libvirtd- Virtualization daemon -
NetworkManager- Network management -
docker- Docker daemon -
postgresql- PostgreSQL database
Example:
systemctl status sshdWhat you'll see:
- Service state (active/inactive, running/stopped)
- Whether it's enabled at boot
- Recent log entries
- Process information
- Loaded configuration file path
Check if a service is active (running):
systemctl is-active servicenameOutput:
-
active- Service is running -
inactive- Service is not running - Exit code 0 = active, non-zero = inactive
Check if a service is enabled (starts at boot):
systemctl is-enabled servicenameOutput:
-
enabled- Service will start at boot -
disabled- Service will not start at boot -
masked- Service is prevented from starting (even manually) - Exit code 0 = enabled, non-zero = disabled/masked
Check if a service has failed:
systemctl is-failed servicenameOutput:
-
failed- Service has failed - Empty output - Service is not in failed state
- Exit code 0 = not failed, non-zero = failed
systemctl list-units --type=service --state=runningWhat this does:
- Shows all services that are currently running
- Displays service name, load state, active state, and description
Example output:
UNIT LOAD ACTIVE SUB DESCRIPTION
abrt-journal-core.service loaded active running ABRT coredumpctl message creator
abrt-oops.service loaded active running ABRT kernel log watcher
abrt-xorg.service loaded active running ABRT Xorg log watcher
abrtd.service loaded active running ABRT Daemon
What each column means:
- UNIT: Service name
- LOAD: Whether the unit file is loaded
- ACTIVE: High-level activation state
- SUB: Low-level activation state (running, dead, etc.)
- DESCRIPTION: What the service does
systemctl list-units --type=service --state=failedWhat this does:
- Shows only services that have failed
- Critical for troubleshooting system issues
- Helps identify what's broken
When to use it:
- System is behaving strangely
- Something isn't working
- After system updates
- Troubleshooting boot issues
If no failed services:
UNIT LOAD ACTIVE SUB DESCRIPTION
0 loaded units listed.
systemctl list-units --type=service --allWhat this does:
- Shows all services regardless of state
- Includes inactive, failed, and running services
- Useful for finding a specific service
systemctl list-unit-files --type=service --state=enabledWhat this does:
- Shows all services that are enabled to start at boot
- Displays the unit file state and preset state
Example output:
UNIT FILE STATE PRESET
abrt-journal-core.service enabled enabled
abrt-oops.service enabled enabled
abrt-vmcore.service enabled enabled
abrt-xorg.service enabled enabled
sudo systemctl start servicenameWhat this does:
- Starts a service immediately
- Does not enable it to start at boot (use
enablefor that) - Requires root privileges (sudo)
Example:
sudo systemctl start sshdWhen to use it:
- Service is stopped and you need it running
- Testing if a service works
- Temporarily starting a disabled service
sudo systemctl stop servicenameWhat this does:
- Stops a running service immediately
- Does not disable it from starting at boot
- Requires root privileges
Example:
sudo systemctl stop sshdWhen to use it:
- Service is misbehaving and needs to be stopped
- Temporarily disabling a service
- Before making configuration changes
sudo systemctl restart servicenameWhat this does:
- Stops and then starts a service
- Applies configuration changes
- Useful after editing service configuration files
Example:
sudo systemctl restart nginxWhen to use it:
- After changing service configuration
- Service is acting strange and needs a fresh start
- Applying updates
sudo systemctl reload servicenameWhat this does:
- Reloads service configuration without stopping it
- Service continues running during reload
- Not all services support reload (some require restart)
Example:
sudo systemctl reload nginxWhen to use it:
- After configuration changes
- When you want to avoid service downtime
- Services that support reload (check with
systemctl status)
sudo systemctl try-restart servicenameWhat this does:
- Restarts the service only if it's currently running
- If the service is stopped, it does nothing
- Safer than regular restart
When to use it:
- Restarting a service that may or may not be running
- Scripts where you're not sure of the service state
sudo systemctl reload-or-restart servicenameWhat this does:
- Tries to reload first (if supported)
- Falls back to restart if reload is not supported
- Best of both worlds
When to use it:
- Applying configuration changes
- When you're not sure if the service supports reload
sudo systemctl enable servicenameWhat this does:
- Configures the service to start automatically at boot
- Does not start the service immediately (use
startfor that) - Creates symlinks to enable the service
Example:
sudo systemctl enable sshdWhen to use it:
- You want a service to start automatically on boot
- Setting up a new service
- After installing a service that should run at boot
sudo systemctl disable servicenameWhat this does:
- Prevents the service from starting at boot
- Does not stop the service if it's currently running
- Removes symlinks that enable the service
Example:
sudo systemctl disable sshdWhen to use it:
- Service should not start automatically
- Reducing boot time
- Disabling unnecessary services
sudo systemctl enable --now servicenameWhat this does:
- Enables the service to start at boot
- Starts the service immediately
- Combines
enableandstartin one command
Example:
sudo systemctl enable --now sshdWhen to use it:
- Setting up a new service that should run now and at boot
- Quick way to enable and start in one step
sudo systemctl disable --now servicenameWhat this does:
- Disables the service from starting at boot
- Stops the service immediately
- Combines
disableandstopin one command
When to use it:
- Completely disabling a service
- Removing a service from the system
sudo systemctl mask servicenameWhat this does:
- Prevents a service from being started (even manually)
- Creates a symlink to
/dev/null - Stronger than disable - service cannot be started at all
When to use it:
- Completely preventing a service from running
- When disable isn't enough
- Troubleshooting service conflicts
Unmasking:
sudo systemctl unmask servicenamesystemctl show servicenameWhat this does:
- Shows all properties of a service
- Displays detailed configuration information
- Useful for troubleshooting
Example:
systemctl show sshdWhat you'll see:
- Service ID and names
- Dependencies (Requires, Wants, After, Before)
- Documentation links
- Description
- Load state
- Active state
- And much more
systemctl list-dependencies servicenameWhat this does:
- Shows what services this service depends on
- Displays the dependency tree
- Helps understand service relationships
Example:
systemctl list-dependencies sshdWhat you'll see:
- Services that must be running before this service
- Services that this service wants (optional)
- Target units (like network.target, sysinit.target)
Reverse dependencies (what depends on this service):
systemctl list-dependencies --reverse servicenamesystemctl cat servicenameWhat this does:
- Shows the service unit file content
- Displays the actual configuration
- Includes drop-in files (overrides)
When to use it:
- Understanding service configuration
- Checking what a service does
- Before making changes
systemctl status servicenameShows recent log entries in the status output.
For more detailed logs:
journalctl -u servicenameFor real-time log following:
journalctl -u servicename -fSee the Journalctl Troubleshooting Guide for more log viewing options.
systemctl list-timersWhat this does:
- Shows all systemd timer units
- Displays when timers will run next
- Shows last run time
Example output:
NEXT LEFT LAST PASSED UNIT ACTIVATES
Thu 2025-11-13 16:04:14 AST 44min Thu 2025-11-13 12:08:03 AST 3h 11min ago dnf-makecache.timer dnf-makecache.service
Fri 2025-11-14 00:00:00 AST 8h Thu 2025-11-13 07:34:00 AST 7h ago unbound-anchor.timer unbound-anchor.service
What each column means:
- NEXT: When the timer will run next
- LEFT: Time until next run
- LAST: When it last ran
- PASSED: Time since last run
- UNIT: Timer unit name
- ACTIVATES: Service that the timer activates
When to use it:
- Checking scheduled tasks
- Understanding system maintenance schedules
- Troubleshooting automated tasks
systemctl --failedWhat this does:
- Lists all failed services
- Quick way to see what's broken
- Equivalent to
list-units --state=failed
sudo systemctl reset-failed servicenameWhat this does:
- Clears the "failed" state from a service
- Useful after fixing a service issue
- Resets the service status
When to use it:
- After fixing a service configuration
- After resolving dependency issues
- Cleaning up service state
Reset all failed services:
sudo systemctl reset-failedsudo systemctl daemon-reloadWhat this does:
- Reloads systemd manager configuration
- Rereads all unit files
- Required after creating or modifying unit files
When to use it:
- After creating a new service file
- After modifying a service unit file
- After installing a new service
- Before starting a newly created service
Important: Always run this after editing service files in /etc/systemd/system/
systemctl statusShows overall system health.
Check if system is degraded:
systemctl is-system-runningPossible outputs:
-
running- System is running normally -
degraded- Some units failed but system is operational -
maintenance- System is in maintenance mode -
initializing- System is still booting -
starting- System is starting up -
stopping- System is shutting down
systemctl list-dependencies servicename --allWhat this does:
- Shows complete dependency tree
- Includes all dependencies recursively
- Shows both required and wanted dependencies
journalctl -u servicenameFilter by priority:
journalctl -u servicename -p errFollow logs in real-time:
journalctl -u servicename -fSince a specific time:
journalctl -u servicename --since "1 hour ago"See the Journalctl Troubleshooting Guide for comprehensive log viewing options.
Problem: A service fails to start.
Solution:
-
Check service status:
systemctl status servicename
-
Check for errors in logs:
journalctl -u servicename -p err
-
Check service dependencies:
systemctl list-dependencies servicename
-
Verify service file:
systemctl cat servicename
-
Try starting with verbose output:
systemctl start servicename systemctl status servicename
Problem: Service starts but immediately stops.
Solution:
-
Check service status for error messages:
systemctl status servicename
-
Follow logs in real-time:
journalctl -u servicename -f
-
Check for configuration errors:
systemctl cat servicename
-
Check system resources:
free -h df -h
Problem: Service works when started manually but doesn't start at boot.
Solution:
-
Check if service is enabled:
systemctl is-enabled servicename
-
If disabled, enable it:
sudo systemctl enable servicename -
Check service dependencies:
systemctl list-dependencies servicename
-
Verify service file for After/Before directives:
systemctl cat servicename
Problem: Port is already in use, preventing service from starting.
Solution:
-
Find what's using the port (example for port 80):
sudo ss -tlnp | grep :80 -
Check the service status:
systemctl status servicename
-
Stop the conflicting service if needed:
sudo systemctl stop conflicting-service
Problem: Service is slow to start.
Solution:
-
Check service status and startup time:
systemctl status servicename
-
Check dependencies:
systemctl list-dependencies servicename
-
Check system load:
uptime systemctl status
-
Review logs for slow operations:
journalctl -u servicename --since "boot"
Problem: Need to understand why a service requires another service.
Solution:
-
View dependencies:
systemctl list-dependencies servicename
-
View reverse dependencies:
systemctl list-dependencies --reverse servicename
-
View service properties:
systemctl show servicename | grep -i depend
System service files:
-
/etc/systemd/system/- Local system service files (highest priority) -
/run/systemd/system/- Runtime service files -
/usr/lib/systemd/system/- Package-installed service files (lowest priority)
User service files:
-
~/.config/systemd/user/- User service files
Drop-in files (overrides):
-
/etc/systemd/system/servicename.service.d/- Service-specific overrides -
/etc/systemd/system/servicename.service.d/override.conf- Common override file
After editing service files: Always run:
sudo systemctl daemon-reloadsystemctl status # Overall system status
systemctl status servicename # Service status
systemctl is-active servicename # Quick active check
systemctl is-enabled servicename # Quick enabled check
systemctl is-failed servicename # Quick failed check
systemctl --failed # List failed servicessudo systemctl start servicename # Start service
sudo systemctl stop servicename # Stop service
sudo systemctl restart servicename # Restart service
sudo systemctl reload servicename # Reload service
sudo systemctl reload-or-restart servicename # Reload or restartsudo systemctl enable servicename # Enable at boot
sudo systemctl disable servicename # Disable at boot
sudo systemctl enable --now servicename # Enable and start
sudo systemctl disable --now servicename # Disable and stop
sudo systemctl mask servicename # Mask service
sudo systemctl unmask servicename # Unmask servicesystemctl list-units --type=service # All services
systemctl list-units --type=service --state=running # Running services
systemctl list-units --type=service --state=failed # Failed services
systemctl list-unit-files --type=service --state=enabled # Enabled services
systemctl list-timers # All timerssystemctl show servicename # Service properties
systemctl list-dependencies servicename # Service dependencies
systemctl cat servicename # Service file content
journalctl -u servicename # Service logssudo systemctl daemon-reload # Reload systemd config
sudo systemctl reset-failed servicename # Reset failed state
sudo systemctl reset-failed # Reset all failedThis guide covered:
- Basic Commands:
- Getting help with
--help - Checking overall system status
- Viewing service status
- Status Checking:
-
status- Detailed service status -
is-active- Quick active check -
is-enabled- Quick enabled check -
is-failed- Quick failed check
- Listing Services:
- Running services
- Failed services
- Enabled services
- All services
- Controlling Services:
- Start, stop, restart, reload
- Try-restart and reload-or-restart
- Enable and disable at boot
- Mask and unmask services
- Service Information:
- Viewing service properties
- Checking dependencies
- Viewing configuration files
- Viewing service logs
- Timers:
- Listing scheduled tasks
- Understanding timer output
- Troubleshooting:
- Finding failed services
- Resetting failed state
- Reloading systemd configuration
- Common troubleshooting scenarios
- Service File Locations:
- Where service files are stored
- Drop-in files and overrides
Next Steps:
- Practice with services on your system
- Combine with
journalctlfor comprehensive troubleshooting - Learn about creating custom service files
- Explore timer units for scheduling tasks
For more advanced topics, see the Journalctl Troubleshooting Guide for detailed log analysis.