An App That Keeps Its Config in Memory Overwrites Live Edits to Its File, So Edit It While It's Stopped

Kubernetes

Some self-hosted apps (LazyLibrarian, for one) read their config file once at startup, keep the settings in memory, and write the whole file back whenever they save: after a change in the UI, after an API call, sometimes on their own at startup. An edit made to the file while the app runs (kubectl exec … sed -i, a script) is therefore at the mercy of the next save, which writes the in-memory values over it. It may even look applied for a while, until a restart or an unrelated save erases it.

The safe pattern: stop the app, edit the file, start it again. In Kubernetes that means scaling the Deployment to zero (the app stops, and may save on the way out, which is why the edit comes only after it's gone), editing from a short-lived pod that mounts the same volume, and scaling back to one: the same moves as repairing a crash-looping app (A Crash-Looping Pod Can't Be Exec'd Into, So Repair Its Volume from a One-Off Job). Keep a copy of the file before editing it.

A Second Trap: Defaults Disappear From the File

Some apps write only the settings that differ from their defaults. A value you set on purpose, but which happens to equal the default, is gone from the file after the next save, and still in effect. A script that checks "is the key in the file with my value?" then sees a change to make every time, and restarts the app for nothing. The check has to read an absent key as the app's default, and the default has to come from the app itself (its source or its docs), not from memory.

What It Looked Like

Wiring my books app from a script (2026-11-27): its API was off, so the API couldn't turn itself on, and the settings had to go into the file. Its log showed the file being saved on its own a few seconds after every start ("Triggered by Git", "Triggered by Newznab"), so a live edit wouldn't have lasted. The script scales it to zero, edits the file from a pod that reuses the app's own image (values passed on stdin, a backup kept), scales it back, and reads the file again. On the second run, the book-source setting I had written was gone from the file: it equals the default. The script now reads each setting's default from the app's source code and counts an absent key as that default.

References

  • LazyLibrarian source (GitLab) - the app in question; its config definitions (ConfigStr, ConfigBool with their defaults) are what the script reads (last checked 2026-11).
  • Kubernetes documentation: Pod lifecycle, termination of Pods - scaling to zero sends SIGTERM and waits for the grace period, which is when an app that saves on shutdown gets to do it (last checked 2026-11).
  • homelab/scripts/wire-media.py (offline_edit, shared since 2026-11-27 with a comics app that keeps its config the same way; wire_lazylibrarian) and homelab/docs/troubleshooting.md, "LazyLibrarian config.ini edits are lost, or a setting disappears" - the code and the incident.

Review cards

Flashcard Why can an edit to a running app's config file be lost even though the file shows the new value?

The app keeps its settings in memory and writes the whole file on its next save (a UI change, an API call, startup), overwriting the edit with the in-memory values.

Flashcard How do you safely change a config file on a Kubernetes app's volume?

Scale the Deployment to zero and wait until the pod is gone (it may save on the way out), edit the file from a short-lived pod that mounts the same claim (backup first), then scale back to one.

Flashcard A script sets a value in an app's config file, but on the next run the key is missing again. What's a likely cause, and how should the check handle it?

The app writes only values that differ from their defaults, so a value equal to the default vanishes from the file while still in effect. The check should treat an absent key as the app's default, read from the app itself.