Last active
September 14, 2020 06:04
-
-
Save vzool/43baaa6fdffd48ab73dae444539fd8ed to your computer and use it in GitHub Desktop.
Check if service is running with CRON job
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Usage: sudo watch-service apcupsd | |
| # Ensure service are running every minute | |
| # * * * * * /root/bin/watch-service apcupsd > /dev/null | |
| service=$@ | |
| /bin/systemctl -q is-active "$service.service" | |
| status=$? | |
| if [ "$status" == 0 ]; then | |
| echo "$service - OK" | |
| else | |
| echo "$service - Starting..." | |
| /bin/systemctl start "$service.service" | |
| fi | |
| # Ref: https://maslosoft.com/kb/watching-for-service-with-cron/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment