Create a gist now

Instantly share code, notes, and snippets.

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