Skip to content

Instantly share code, notes, and snippets.

@gerdriesselmann
Created December 30, 2014 21:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerdriesselmann/d7c034c4156759da9c09 to your computer and use it in GitHub Desktop.
Save gerdriesselmann/d7c034c4156759da9c09 to your computer and use it in GitHub Desktop.
Restart service if binary has changed
#!/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