Systemd Service Troubleshooting: Complete Guide to Fix Failed Services
Understanding Systemd Services
Systemd is the init system used by most modern Linux distributions. When services fail, you need to know how to troubleshoot them effectively.
Check Service Status
systemctl status servicename
systemctl list-units --failed
systemctl --failedView Service Logs
journalctl -u servicename
journalctl -u servicename --since today
journalctl -u servicename -f # Follow logsCommon Issues and Fixes
Service Fails to Start
# Check for errors
journalctl -xe
# Verify configuration
systemd-analyze verify /etc/systemd/system/servicename.service
# Check dependencies
systemctl list-dependencies servicenamePermission Denied Errors
# Check file permissions
ls -l /etc/systemd/system/servicename.service
# Fix ownership
sudo chown root:root /etc/systemd/system/servicename.service
sudo chmod 644 /etc/systemd/system/servicename.servicePort Already in Use
# Find what's using the port
sudo lsof -i :80
sudo ss -tulpn | grep :80
# Kill the process
sudo kill -9 PIDService Management Commands
# Start service
sudo systemctl start servicename
# Stop service
sudo systemctl stop servicename
# Restart service
sudo systemctl restart servicename
# Reload configuration
sudo systemctl reload servicename
# Enable on boot
sudo systemctl enable servicename
# Disable on boot
sudo systemctl disable servicenameAdvanced Troubleshooting
Masked Services
# Check if masked
systemctl status servicename
# Unmask
sudo systemctl unmask servicenameDependency Issues
# View dependency tree
systemctl list-dependencies servicename --all
# Check what depends on this service
systemctl list-dependencies servicename --reverseBest Practices
- Always check logs with journalctl first
- Verify service file syntax before reloading
- Use systemctl daemon-reload after editing service files
- Test services in non-production first
- Document custom service configurations