A mutual-exclusion lock held ON the target, so two people (or a person and a cron) cannot deploy to the same machine at the same time.
class MMO\admin\helpers\RemoteLock
Namespace
MMO\admin\helpers
The lock is a DIRECTORY, not a file: `mkdir` is atomic and fails when the directory already exists, on every
POSIX filesystem and over NFS -- which `test -e && touch` is not. That matters here because each command is a
separate ssh round-trip, so anything relying on a shell-level `flock` holding across commands would not work.
Breaking a lock is atomic for the same reason. An earlier version, on finding a stale lock, simply warned and
carried on -- which let two runners that both observed the same stale lock both decide they now held it, the
exact situation the lock exists to prevent. Here the breaker `mv`s the directory aside and `mkdir`s a fresh
one: exactly one runner can win that sequence, and the loser is told so.
Take an existing lock away from whoever holds it, atomically.
protected function breakLock(string $held): void`mv` of a directory onto a new name is a single rename: exactly one of two concurrent breakers can
succeed, and the `mkdir` that follows decides the winner a second time. A runner that loses either step
stops rather than assuming it won.