lugorguk / lug.org.uk-website

Website of the UK Linux User Groups organisation
Creative Commons Zero v1.0 Universal
5 stars 5 forks source link

Needs automatic update mechanism #10

Closed JonTheNiceGuy closed 6 years ago

JonTheNiceGuy commented 6 years ago

Code from oggcamp's hosting is to have a script in $HOME with the following content:

#!/bin/bash
cd $HOME/jekyll
git fetch origin
reslog=$(git log HEAD..origin/master --oneline)
if [[ "${reslog}" != "" ]] ; then
# there are new changes: completing the pull
  git merge origin/master
  jekyll build -d $HOME/public_html
fi

This then is scheduled via crontab, however, if there's any reason you can't reach the origin (via git pull) then it gets noisy very quickly. We could do with some sort of failure detection and threshold. Perhaps this untested bash script (to replace the single "git fetch origin" line above) covers it?

if ! git fetch origin 2>/tmp/tempfile ; then
  if [ -e $HOME/.failure_status ]; then
    source $HOME/.failure_status
  else
    FAILURE_STATUS=0
  fi
  if [ -z "$FAILURE_THRESHOLD" ]; then
    FAILURE_THRESHOLD=5
  fi
  if [ $FAILURE_STATUS -gt $FAILURE_THRESHOLD ]; then
    cat /tmp/tempfile
    rm /tmp/tempfile
    FAILURE_STATUS=0
  else
    FAILURE_STATUS=$((FAILURE_STATUS+1))
  fi
  echo "FAILURE_STATUS=$FAILURE_STATUS" > $HOME/.failure_status
fi
rm -f /tmp/tempfile
JonTheNiceGuy commented 6 years ago

For the short-term, I have copied into the testsite path the update_site script, and tweaked it to change "$HOME" for "BASEDIR". I've then created a crontab entry for root, showing the following:

*/5 * * * * BASEDIR=/home/groups/testsite.lug.org.uk /home/groups/testsite.lug.org.uk/update_site 2>&1 | mail jon@sprig.gs -E -s update_site testsite.lug.org.uk

This will tide us over for the next few days, until I figure out something a little more permanant!

JonTheNiceGuy commented 6 years ago

Considering using this instead: https://github.com/JonTheNiceGuy/git-autoupdate - thoughts?

gwestwood commented 6 years ago

Sounds perfect.