#!/bin/bash

CONSUL_LOG_FILE={{ consul_log_file }}

_cur=0
_trigger=3

_restart_if_needed () {
  ((_cur++))
  if (( _cur >= _trigger )); then
    systemctl restart consul
    _cur=0
  fi
}

tail -F -n 0 $CONSUL_LOG_FILE |
grep --line-buffered 'Coordinate update error' |
while read line ; do _restart_if_needed ; done
