Use leveldb database lock for concurrent upgrade protection (fixes #703)

Doesn't work if config directories are different though
Merge remote-tracking branch 'origin/pr/731'

* origin/pr/731:
  Use leveldb database lock for concurrent upgrade protection (fixes #703)