Last active
April 13, 2019 18:22
-
-
Save caasi/d7039c2775fbedf3ddcdedfa1ab41451 to your computer and use it in GitHub Desktop.
A simple watchdog script
This file contains 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
*/5 * * * * /root/bin/watchdog.sh redis:redis/redis-server.pid logbot logbot5000 logbot6000 |
This file contains 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/sh | |
for ARG in $@; do | |
# extract service name and pid file path | |
NAME=`echo $ARG | cut -d":" -f1` | |
PID_PATH=`echo $ARG | cut -d":" -f2` | |
if [ "$NAME" = "$PID_PATH" ]; then | |
PID_PATH="$PID_PATH.pid" | |
fi | |
# check service status | |
CMD="service $NAME start" | |
if [ -f "/var/run/$PID_PATH" ]; then | |
PID=`cat /var/run/$PID_PATH` | |
if [ ! -d "/proc/$PID" ]; then | |
echo $CMD | |
$CMD | |
fi | |
else | |
echo $CMD | |
$CMD | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment