Due to the current maintenance break, I have seen a lot of people complaining about loosing their gems. I myself have not had this problem as I don't boost my barracks often.
Maybe 2 hours before a maintenance if you were to try to boost your barracks it could either give you a warning asking you "Are you sure you want to boost your barracks? Maintenance break is soon chief!" or it could just say "boosting not available, maintenance break soon."
Maybe a bit hard to put into the game but just an idea.
Thanks
~minimitch