Best way to test if a systemd service is running in bash script

systemctl is-active application.service
systemctl is-enabled application.service
systemctl is-active --quiet service

will exit with status zero if service is active, non-zero otherwise, making it ideal for scripts:

systemctl is-active --quiet service && echo Service is running


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.