Ensure writes to runtime.json are atomic

By writing to a temporary file `runtime.json.tmp` and the renaming it
the risk of other processes reading a truncated file is eliminated.