Skip to content

Instantly share code, notes, and snippets.

@ilyaevseev
Created May 28, 2025 21:01
Show Gist options
  • Save ilyaevseev/00ba6eaf9613a7e0fa4cd591ced7cc2e to your computer and use it in GitHub Desktop.
Save ilyaevseev/00ba6eaf9613a7e0fa4cd591ced7cc2e to your computer and use it in GitHub Desktop.
Cassandra NoSQL quick+dirty watchdog script
#!/bin/sh
test "$(systemctl is-active cassandra)" = "active" || exit 0
pid="$(systemctl show -p MainPID --value cassandra)"
test "$pid" = "" && exit 0
test "$pid" = "0" && exit 0
UPTIME="$(ps -o etimes:1 --no-headers -p $pid)"
test "$UPTIME" = "" && exit 0
test "$UPTIME" -lt "600" && exit 0
ACTIVE="$(timeout 20 nodetool -Dcom.sun.jndi.rmiURLParsing=legacy info | egrep -c 'active *: true')"
test "$ACTIVE" -ge 3 && exit 0
logger -p user.notice -t "${0##*/}" -- "restart"
systemctl restart cassandra
## END ##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment