Systemd Service Troubleshooting: Complete Guide to Fix Failed Services

By Tech Writer Linux
Master systemd troubleshooting with this comprehensive guide. Learn how to diagnose failed services, read logs, and fix common systemd issues in Linux.

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 --failed

View Service Logs

journalctl -u servicename
journalctl -u servicename --since today
journalctl -u servicename -f  # Follow logs

Common 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 servicename

Permission 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.service

Port Already in Use

# Find what's using the port
sudo lsof -i :80
sudo ss -tulpn | grep :80

# Kill the process
sudo kill -9 PID

Service 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 servicename

Advanced Troubleshooting

Masked Services

# Check if masked
systemctl status servicename

# Unmask
sudo systemctl unmask servicename

Dependency Issues

# View dependency tree
systemctl list-dependencies servicename --all

# Check what depends on this service
systemctl list-dependencies servicename --reverse

Best 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