We used to keep our Nagios config up to date through SVN, with users commiting their changes and a script running every 15 minutes. The script checked for updates, then checked those updates parsed the config check, then reloaded the config. Nice and simple, did the job perfectly.
We recently moved to GIT as part of a wider migration towards GIT for other projects and I'm having difficulty reworking this script to match.
Here is the original SVN version:
cd /usr/local/nagios
RESULT=`svn update | grep Updated | wc -l`
echo $RESULT
if [ "$RESULT" != "0" ]; then
/etc/init.d/nagios reload
fi
cd -
And here is my best efforts so far with GIT:
cd /usr/local/nagios
RESULT=`git pull 2>&1 | grep Unpacking | wc -l`
echo $RESULT
if [ "$RESULT" != "0" ]; then
/etc/init.d/nagios reload
fi
cd -
The problem I'm having is I can't seem to get the output parseable so I can match against it. I thought about going a different route by examining the most recent commit in the local working copy, and then checking if the remote most recent commit was different. I can't figure out though how to get this information.
I'm pretty new to GIT and this is driving me nuts, so my huge thanks in advance for any assistance!
You can check if the tip (a.k.a. HEAD) of the local branch changed before and after you pull.
You could use the
post-merge
hook, which will trigger only when there is a merge on the client side and if there are no conflicts.Content of the
post-merge
:Copy the file in
.git/hooks
on the client side and don't forget tochmod u+x post-merge
If you want to know whether there are new changes to fetch, you can compare the output of the following commands:
If the hashes differ, there are changes to fetch:
Use the checksums displayed by
git log
. For example: