The Computer Oracle

Preferred place to store configuration files that change often

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Orient Looping

--

Chapters
00:00 Preferred Place To Store Configuration Files That Change Often
01:37 Accepted Answer Score 26
03:30 Thank you

--

Full question
https://superuser.com/questions/631859/p...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux

#avk47



ACCEPTED ANSWER

Score 26


The Filesystem Hierarchy Standard requires that configuration files for something installed under /opt/xyz should go into /etc/opt/xyz, where the xyz must match. That is, an application installed in a directory under /opt which requires host-specific configuration files should have a matching directory under /etc/opt into which those configuration files go.

The purpose of /etc (host-specific system configuration) is simply stated as:

The /etc hierarchy contains configuration files. A "configuration file" is a local file used to control the operation of a program; it must be static and cannot be an executable binary.

Of course, no configuration is totally static, but I'd take "static" in this context to mean roughly "does not change without administrator intervention".

/etc/opt is more specific, and its purpose is stated as:

Host-specific configuration files for add-on application software packages must be installed within the directory /etc/opt/<subdir>, where <subdir> is the name of the subtree in /opt where the static data from that package is stored.

Since you are installing the software under /opt, the configuration files thus should go into a corresponding subdirectory or hierarchy under /etc/opt.

Of course, nothing requires that your system conforms to the FHS, but it'll make it much easier for others to find any files they might be looking for since they'll know where they can expect to find them.

Since this is about internally developed software I would also strongly suggest that you make the location configurable. Even if it is only configurable through a macro declaration done in the makefile and effected through a complete rebuild from source, that is still much better than hardcoding a specific location into the source code everywhere you want to open a configuration file.