Filesystem and configuration
Configuration and generated files
Edit the source configuration a program owns instead of changing generated output that will be overwritten.
8 minute lesson
System-wide configuration commonly lives under /etc. A service may use one main file, a directory of smaller fragments, environment files, or configuration generated by another tool.
Do not edit the first file that contains the value you want. First find which file is the source of truth.
For example, a file may begin with a warning like this:
# This file is managed automatically. Changes will be overwritten.
Editing it may appear to work until the next package update, deployment, or configuration-generation command removes your change.
Inspect ownership before editing
Check which package owns a file:
dpkg -S /path/to/file
Read the service documentation and inspect its unit definition:
systemctl cat notes-api.service
This can reveal environment files, command-line flags, and drop-in configuration. For systemd units, prefer a supported drop-in created with systemctl edit over modifying a package-owned unit file directly.
Use a safe change sequence
- Save the current working file or record its version-control state.
- Change one thing.
- Run the application’s configuration check.
- Reload or restart only when the check succeeds.
- Verify the service and its real behavior.
Nginx, for example, can validate its complete configuration before a reload:
sudo nginx -t
sudo systemctl reload nginx
systemctl status nginx --no-pager
Do not reload after a failed validation. Restore the previous file if the new configuration does not behave as expected.
Package updates can ask about local changes
When you modify a package-managed configuration file, an update may ask whether to keep your version or install the maintainer’s version. Read the diff. Neither choice is automatically correct.
My advice is to keep custom configuration small and placed in supported fragment directories. This makes upgrades and review much easier.
Try this: choose one service on a test machine. Find its unit file, configuration path, validation command, and reload command without changing anything.
Lesson completed