Bash

Check Systemd Service Is Running

admin by @admin ADMIN
1h ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
`systemctl is-active` is the right tool — exit code 0 if running, non-zero otherwise. Combine with restart-on-fail for poor-man's supervision.
Bash
Raw
# Quick check (suitable for use in scripts)
if systemctl is-active --quiet nginx; then
    echo "nginx is running"
fi

# Restart if down
if ! systemctl is-active --quiet php8.3-fpm; then
    echo "php-fpm down, restarting…"
    systemctl restart php8.3-fpm
fi

# Detailed status
systemctl status nginx --no-pager

# Recent log lines from a unit
journalctl -u nginx -n 50 --no-pager
journalctl -u nginx --since "10 minutes ago"

# Watch a service's logs in real time
journalctl -u myapp -f
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.