Skip to content

Instantly share code, notes, and snippets.

@vzool
Last active September 14, 2020 06:04
Show Gist options
  • Select an option

  • Save vzool/43baaa6fdffd48ab73dae444539fd8ed to your computer and use it in GitHub Desktop.

Select an option

Save vzool/43baaa6fdffd48ab73dae444539fd8ed to your computer and use it in GitHub Desktop.
Check if service is running with CRON job
#!/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