(Originally asked on Serverfault here )

What do you want to know, exactly?

Is there a simple tool which you can call on a filename which:

  • attempts to flock the file you want to edit (and lets you know if that failed, and when the lock was acquired by the last person to acquire it), then (if successful)
  • copies the file to a working copy
  • opens an editor on that working copy, and once the editor exits
  • runs an XML validator against the saved working copy to verify that it passes at least a basic sanity check, and then
  • if that check is passed, overwrites the original with the working copy, and
  • if that check is not passed, gives a helpful error message and asks you if you want to return to the working copy or exit without saving

Ideally, there would be a general-purpose program for this which can validate multipe different file formats depending on arguments (e.g. XML, ini, YAML, JSON, etc.), but honestly all I would need this for is XML. Bonus points if it's in the standard debian repos.

While I could write it myself, that'd be silly if something already existed.

Why do you want this?

I currently work in an environment where not everything is automated. We have hundreds of machines, and we've been running many of them since before the rollout of our automated infrastructure.

It's sad, but it's reality, and it's going to be reality for at least the next year or two.

In the meanwhile, we have some files which we'll need to manually edit (primarily XML), and in so doing two problems tend to arise, namely:

  1. Because two different issue tickets sometimes end up requiring modification to the same file, two people sometimes end up editing the same file and the race condition results in- at best- one persons edits being entirely lost, and

  2. Even if only one person is editing, the server that's using this config files will see they've changed and pick them up once they've been saved. However, being human, sometimes people forget an '=', or a '/', and in between when they save the file and when they realize they screwed up, the server is screwed up.

  • git is an obvious, if incorrect, solution. Yes, git provides versioning and validation, but it doesn't solve the problem of multiple people modifying the same file simultaneously. It could be used in such a way that is guaranteed, but the additional overhead associated with setting that up is greater than the advantage provided. – Parthian Shot Jul 22 '16 at 21:00
  • At the end of the day we'll be using a real configuration management tool (which we're already using for plenty of things, anyway). – Parthian Shot Jul 22 '16 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.