Created
December 30, 2014 21:11
-
-
Save gerdriesselmann/d7c034c4156759da9c09 to your computer and use it in GitHub Desktop.
Restart service if binary has changed
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/bash | |
SERVICE="{service_name}" | |
FILE="{/path/to/service/binary}" | |
FINGERPRINT="/root/watchers/$SERVICE.md5" | |
fingerprint_expected=$(/usr/bin/md5sum "$FILE") | |
if [ ! -e "$FINGERPRINT" ] | |
then | |
echo "$fingerprint_expected" > "$FINGERPRINT" | |
fi | |
fingerprint_content=$(/bin/cat "${FINGERPRINT}") | |
if [ "$fingerprint_expected" != "$fingerprint_content" ]; | |
then | |
# Service has new binary | |
echo "$fingerprint_expected" > "$FINGERPRINT" | |
echo "Service $SERVICE has changed, trying to restart" | |
/usr/sbin/service "$SERVICE" restart | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment