Skip to content

Handle read-only config file gracefully in Docker Swarm#157

Open
mherman22 wants to merge 1 commit into
intrahealth:masterfrom
mherman22:fix/readonly-config-file
Open

Handle read-only config file gracefully in Docker Swarm#157
mherman22 wants to merge 1 commit into
intrahealth:masterfrom
mherman22:fix/readonly-config-file

Conversation

@mherman22

Copy link
Copy Markdown

Problem

In Docker Swarm, config files are mounted as read-only Docker configs. When updateConfigFile() in generalMixin.js tries to write back to the config file (e.g., to update sync.lastFHIR2ESSync after an ES re-index), fs.writeFile fails and throw err on line 53 crashes the entire process.

This affects any deployment using Docker Swarm or Kubernetes where config files are immutable.

Error: EROFS: read-only file system, open '/src/server/config/config_docker.json'

Fix

  • config.set() still updates the in-memory config (always works, keeps runtime state correct)
  • fs.writeFile failure now logs a warning instead of crashing
  • require(configFile) failure is also handled (in case the file is inaccessible)
  • The callback is always invoked so the calling code continues normally

The in-memory config remains correct for the duration of the process. On restart, the mounted config file is re-read — so values like lastFHIR2ESSync will reset to whatever is in the Docker config, which means the next startup will do a full ES re-sync from that timestamp. This is expected behavior in immutable infrastructure.

Fixes #139

updateConfigFile() calls fs.writeFile on the config JSON file after
updating the in-memory config via config.set(). In Docker Swarm,
config files are mounted read-only, so the write fails and throw err
crashes the entire process.

Change to:
- Keep config.set() for in-memory state (always works)
- Log a warning instead of crashing if fs.writeFile fails
- Also handle the case where require(configFile) fails

The in-memory config remains correct for the duration of the process.
On restart, the config file is re-read from the Docker config mount,
so values like lastFHIR2ESSync will reset — but this is expected
behavior in immutable infrastructure.

Fixes intrahealth#139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Running OpenCR in swarm fails with config files that are read-only

1 participant