Ensure writes to runtime.json are atomic

By writing to a temporary file `runtime.json.tmp-$random` and the
renaming it the risk of other processes reading a truncated file is
eliminated.
Merge pull request #93 from keis/atomic-file-write

Ensure writes to runtime.json are atomic