What's Actually Happening
Linux systemd services fail to start or enter failed state. Services show inactive or failed status, applications are unavailable, or daemons exit unexpectedly.
The Error You'll See
Service failed:
```bash systemctl status nginx
nginx.service - nginx Loaded: loaded (/lib/systemd/system/nginx.service; enabled) Active: failed (Result: exit-code) ```
Journal logs:
```bash journalctl -u nginx
nginx.service: Main process exited, code=exited, status=1/FAILURE ```
Start failure:
```bash systemctl start nginx
Job for nginx.service failed because the control process exited with error code. ```
Why This Happens
- 1.Config error - Service configuration invalid
- 2.Port in use - Port already taken by another service
- 3.Permission denied - Insufficient permissions
- 4.Missing dependency - Required dependency not met
- 5.Resource exhausted - Out of memory or disk space
- 6.Binary missing - Executable not found
- 7.Environment issue - Wrong environment variables
Step 1: Check Service Status
```bash systemctl status service-name
systemctl is-active service-name
systemctl is-enabled service-name
systemctl list-units --failed
systemctl list-units --all | grep service-name ```
Step 2: Check Journal Logs
```bash journalctl -u service-name
journalctl -u service-name -f
journalctl -u service-name --since "1 hour ago"
journalctl -u service-name -n 50
journalctl -u service-name -p err ```
Step 3: Check Service Configuration
```bash systemctl cat service-name
cat /etc/systemd/system/service-name.service
cat /lib/systemd/system/service-name.service
# Validate service file: systemd-analyze verify /etc/systemd/system/service-name.service ```
Step 4: Check Port Availability
```bash ss -tlnp | grep port
netstat -tlnp | grep port
lsof -i :port
# Check what's using the port: ss -tlnp | grep 80
# Kill process if needed: kill -9 PID ```
Step 5: Check Permissions
```bash ls -la /path/to/executable
ls -la /path/to/config
# Check if user can run: su -s /bin/bash service-user -c "/path/to/executable"
# Fix permissions: chmod +x /path/to/executable chown user:group /path/to/file ```
Step 6: Check Dependencies
```bash systemctl list-dependencies service-name
# Check dependency status: systemctl status dependency.service
# Check After= and Requires=: systemctl cat service-name | grep -E "After|Requires|Wants" ```
Step 7: Check Resources
```bash free -h
df -h
top
# Check for OOM: dmesg | grep -i "out of memory"
journalctl -u service-name | grep -i oom
# Check file descriptors: lsof -p $(pidof process-name) | wc -l ulimit -n ```
Step 8: Manual Debug
```bash # Run service manually: /path/to/executable --config /path/to/config
# Or as service user: su -s /bin/bash service-user -c "/path/to/executable"
# Check output: /path/to/executable --debug
# Test with strace: strace -f /path/to/executable ```
Step 9: Restart and Reset
```bash # Reset failed state: systemctl reset-failed service-name
# Reload systemd: systemctl daemon-reload
# Restart service: systemctl restart service-name
# Enable and start: systemctl enable service-name systemctl start service-name ```
Step 10: Monitor Service
```bash watch -n 5 systemctl status service-name
# Check service restarts: journalctl -u service-name | grep -i restart
# Monitor resources: watch -n 5 'ps aux | grep service-name'
# Check service uptime: systemctl show service-name --property ActiveEnterTimestamp ```
Linux Service Failed Checklist
| Check | Command | Expected |
|---|---|---|
| Service status | systemctl status | Active |
| Journal logs | journalctl -u | No errors |
| Port available | ss -tlnp | Not in use |
| Permissions | ls -la | Correct |
| Dependencies | systemctl status | All active |
| Resources | free/df | Available |
Verify the Fix
```bash systemctl status service-name
systemctl is-active service-name
journalctl -u service-name --since "5 min ago"
ss -tlnp | grep port
systemctl restart service-name
curl localhost:port ```
Related Issues
- [Fix Linux System Service Failed](/articles/fix-linux-system-service-failed)
- [Fix Linux System Disk Full](/articles/fix-linux-system-disk-full)
- [Fix Nginx Service Failed](/articles/fix-nginx-service-failed)