Service Check Commands for CentOS
Comprehensive guide to checking, monitoring, and managing systemd services on CentOS systems with 33+ commands.
Basic Service Status Commands​
1. Check Service Status​
sudo systemctl status nginx
sudo systemctl status nginx mysql php-fpm
sudo systemctl list-units --type=service
sudo systemctl list-units --type=service --state=active --no-pager
sudo systemctl list-units --type=service --state=running --no-pager
Output shows:
- Service name
- Loaded status
- Active status
- Recent logs
2. Check Service Enabled Status​
sudo systemctl is-enabled nginx
sudo systemctl list-unit-files --type=service | grep enabled
sudo systemctl list-unit-files --type=service --state=enabled --no-pager
Return values:
enabled- Starts automatically on bootdisabled- Does not start on bootstatic- Cannot be enabled/disabledmasked- Service is masked
3. Check if Service is Running/Stopped​
sudo systemctl is-active nginx
sudo systemctl is-enabled nginx
sudo systemctl list-units --failed --type=service --no-pager
sudo systemctl list-units --type=service --all --state=failed
Return values:
active- Service is runninginactive- Service is stoppedfailed- Service failed to startactivating- Service is startingdeactivating- Service is stopping
Advanced Service Monitoring Commands​
4. Check Service Resource Usage​
systemctl show -p MemoryCurrent -p CPUUsageNSec -p MainPID nginx
ps aux | grep nginx | grep -v grep
ps aux | grep nginx | awk '{print $2, $3, $4, $11}' | column -t
pstree -p $(systemctl show -p MainPID --value nginx)
5. Check Service Dependencies​
sudo systemctl show -p Requires nginx
sudo systemctl show -p RequiredBy nginx
sudo systemctl show -p Wants -p WantedBy nginx
sudo systemctl show -p Before -p After nginx
6. Check Service Restart Policy​
sudo systemctl show -p Restart -p RestartSec nginx
sudo systemctl show nginx | grep -E "^(Restart|RestartSec|TimeoutStopSec|TimeoutStartSec)"
sudo systemctl show -p Type nginx
Check Specific Common Services​
7. Check Nginx Service​
sudo systemctl status nginx
sudo nginx -t
ps aux | grep nginx | grep -v grep
sudo ss -tlnp | grep nginx
sudo tail -20 /var/log/nginx/error.log
sudo tail -20 /var/log/nginx/access.log
8. Check MySQL/MariaDB Service​
sudo systemctl status mysql
sudo systemctl status mariadb
ps aux | grep mysql | grep -v grep
sudo ss -tlnp | grep mysql
sudo tail -20 /var/log/mysql/error.log
mysql -u root -p -e "status;"
mysql -u root -p -e "SHOW PROCESSLIST;"
9. Check PHP-FPM Service​
sudo systemctl status php-fpm
php-fpm -v
ps aux | grep php-fpm | grep -v grep
sudo ss -tlnp | grep php-fpm
php-fpm -t
sudo tail -20 /var/log/php-fpm/error.log
10. Check Apache/HTTPD Service​
sudo systemctl status apache2
sudo systemctl status httpd
sudo apache2ctl configtest
sudo httpd -t
ps aux | grep apache | grep -v grep
sudo ss -tlnp | grep apache
sudo tail -20 /var/log/apache2/error.log
sudo tail -20 /var/log/httpd/error_log
11. Check Redis Service​
sudo systemctl status redis
ps aux | grep redis | grep -v grep
sudo ss -tlnp | grep redis
redis-cli
redis-cli INFO
redis-cli INFO memory
12. Check PostgreSQL Service​
sudo systemctl status postgresql
ps aux | grep postgres | grep -v grep
sudo ss -tlnp | grep postgres
sudo tail -20 /var/log/postgresql/postgresql.log
psql -U postgres -l
13. Check SSH Service​
sudo systemctl status sshd
ps aux | grep sshd | grep -v grep
sudo ss -tlnp | grep sshd
sudo sshd -t
sudo tail -20 /var/log/auth.log
sudo tail -20 /var/log/secure
Service Control Commands​
14. Start/Stop/Restart Services​
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx
sudo systemctl enable nginx
sudo systemctl disable nginx
sudo systemctl mask nginx
sudo systemctl unmask nginx
15. Restart Multiple Services​
sudo systemctl restart nginx mysql php-fpm
sudo systemctl restart datadog-agent
sudo systemctl restart nginx && sudo systemctl restart php-fpm && sudo systemctl restart mysql
Service Logging and Troubleshooting​
16. Check Service Logs​
sudo journalctl -u nginx -n 20
sudo journalctl -u nginx -f
sudo journalctl -u nginx --since "2025-10-23 10:00:00"
sudo journalctl -u nginx -p err
sudo journalctl -u nginx -p warn
sudo journalctl -u nginx -r -n 50
sudo journalctl -u nginx > /tmp/nginx_logs.txt
17. Check Service Startup Errors​
sudo systemctl status nginx
sudo journalctl -u nginx -n 100
sudo systemctl list-units --failed
sudo journalctl -u nginx -p err --since today
sudo systemctl cat nginx
18. Check Service Configuration​
sudo systemctl cat nginx
sudo systemctl show nginx
sudo systemctl show nginx -p ExecStart -p ExecReload -p ExecStop
sudo systemctl show -p Environment nginx
sudo systemctl show -p WorkingDirectory nginx
Port and Network Service Checks​
19. Check Services by Port​
sudo ss -tlnp
sudo ss -tlnp | grep :80
sudo lsof -i :8080
sudo netstat -tulnp | grep LISTEN
sudo ss -tcp -listen -process
20. Check UDP Services​
sudo ss -ulnp
sudo netstat -ulnp
sudo ss -u | grep 53
Comprehensive Service Monitoring​
21. Check All Services Summary​
sudo systemctl list-units --type=service --all
sudo systemctl list-units --type=service --all --no-pager | grep -E 'nginx|mysql|php|redis|datadog'
sudo systemctl list-units --type=service | tail -1
sudo systemctl list-units --type=service --all --state=loaded
22. Check Failed/Problematic Services​
sudo systemctl list-units --failed --type=service
sudo systemctl status nginx 2>&1 | grep -i error
sudo systemctl list-units --type=service --state=inactive
sudo systemctl list-units --type=service --state=failed
23. Monitor Service Performance​
top -p $(systemctl show -p MainPID --value nginx)
cat /proc/$(systemctl show -p MainPID --value nginx)/limits
ls -la /proc/$(systemctl show -p MainPID --value nginx)/fd | wc -l
watch -n 1 'systemctl show -p MemoryCurrent nginx'
Service Restart Policies​
29. Check and Set Restart Policy​
sudo systemctl show -p Restart nginx
sudo systemctl show -p RestartSec nginx
sudo systemctl edit nginx
# [Service]
# Restart=always
# RestartSec=10s
30. Automatic Service Recovery​
sudo systemctl show -p Restart -p RestartSec nginx
sudo journalctl -u nginx | grep "Restart count"
sudo systemctl show -p WatchdogSec nginx
Service Dependency Management​
31. Check Service Dependencies​
sudo systemctl show -p Before nginx
sudo systemctl show -p After nginx
sudo systemctl show -p Requires nginx
sudo systemctl show -p RequiredBy nginx
sudo systemctl show -p Wants nginx
32. Manage Service Boot Order​
systemd-analyze plot
systemd-analyze blame
systemd-analyze critical-chain
systemd-analyze verify /etc/systemd/system/nginx.service
Quick Reference Table​
| Task | Command |
|---|---|
| Check service status | sudo systemctl status nginx |
| Start service | sudo systemctl start nginx |
| Stop service | sudo systemctl stop nginx |
| Restart service | sudo systemctl restart nginx |
| Enable service | sudo systemctl enable nginx |
| Disable service | sudo systemctl disable nginx |
| Is service running | sudo systemctl is-active nginx |
| Is service enabled | sudo systemctl is-enabled nginx |
| View logs | sudo journalctl -u nginx -f |
| Check errors | sudo journalctl -u nginx -p err |
| List all services | sudo systemctl list-units --type=service |
| List running services | sudo systemctl list-units --type=service --state=running |
| List failed services | sudo systemctl list-units --failed |
| Check listening ports | sudo ss -tlnp |
| Check port usage | sudo lsof -i :8080 |
| Show service file | sudo systemctl cat nginx |
| Show service properties | sudo systemctl show nginx |
| Reload configuration | sudo systemctl reload nginx |
| Enable debug logging | sudo journalctl -u nginx -p debug |
| Export logs | sudo journalctl -u nginx > /tmp/nginx.log |
Related Documentation​
- One-Line Bash Commands - Essential Linux one-liners
- Datadog CentOS Setup - Datadog installation and configuration
- Datadog Proxy Testing - Network proxy diagnostics