Skip to content

Instantly share code, notes, and snippets.

@yakaviuk
Last active February 27, 2024 23:06
Show Gist options
  • Save yakaviuk/04fac5023c142b7217631069c77d4848 to your computer and use it in GitHub Desktop.
Save yakaviuk/04fac5023c142b7217631069c77d4848 to your computer and use it in GitHub Desktop.
bash script
#!/bin/bash
service=$@
/bin/systemctl -q is-active "$service.service"
status=$?
if [ "$status" == 0 ]; then
echo "OK"
else
/bin/systemctl start "$service.service"
fi
@yakaviuk
Copy link
Author

usage:
./watch-service.sh postgresql

Cron:
*/2 * * * * /opt/watch-service.sh postgresql > /dev/null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment