Add deploy locking

It's a bit ugly and the documentation isn't there, but it does the job.  Will need to clean it up a lot, there's a few places I'm not happy with repetition.

Tagging @jmacadam and @doomspork for review.