You are not logged in.

#1 2019-07-16 10:08:34

apollo22
Member
Registered: 2018-04-13
Posts: 31

How do you manage configuration files path ?

I am having some difficulties to set configuration files path when programming (in any language), because of the diversity of installation methods.

For example, an application might be installed by the system administrator in `/usr/bin` (or `/usr/local/bin`), in this case, one would expect the configuration to be in `/etc`.

However, it could also be installed using a drop in folder in `/opt`, in this case one could except the configuration in `/opt/<package-name>/config`.

For development, the `/opt/` scheme could be used, but what about when you are developing modules that can be configured, you need the ability to use both the parent path when used as a module, and another path when the module is developed / used alone.

Another case is when the application is installed by a user (either as drop in somewhere or installed in ~/bin or equivalent).


Do you think detecting the installation path to set the configuration files path is adequate ? Do you know of any library using this scheme or implementing it for other to use ?

Offline

#2 2019-07-16 12:55:19

ayekat
Member
Registered: 2011-01-17
Posts: 1,356
Website

Re: How do you manage configuration files path ?

First, /opt is a different thing: if you structure your program in a way that it can nicely integrate into a system (i.e. install files into the appropriate directories like bin, lib, share, etc and others), you don't need to care about /opt. It's mainly there for application "bundles" that put everything in a single directory and cannot be properly split up (usually proprietary software) (note that hier(7) defines this a bit differently, though).

About /usr/local or /usr (often referred to as the installation "prefix"), you should let the system administrator (user, packager, … whoever builds and installs your software) choose. In addition to the prefix, the location of the system-wide configuration directory (/usr/local/etc or /etc) should also be configurable, typically through some build-time variable like "sysconfdir" or the like (although, some build systems appear smart enough to figure out that if the prefix is /usr, the sysconfdir is /etc).

Choosing between system-config and user-config is orthogonal to the above issue. It's not a problem of "how is it built/installed", but rather "how is supposed to be used":

  • If your software is meant to run as a daemon process (like a web server or a log daemon or whatnot), it's safe to assume that it's probably going to be run under a system user, and having it read its configuration from the system-wide configuration directory (e.g. /etc) would be more appropriate. Note that you should still allow people to choose a different location at runtime, e.g. through a command line flag, because a web server can also be run under a regular user.

  • If your software is meant to be mainly run by a regular user, reading the configuration in the user configuration directory makes most sense.

apollo22 wrote:

Another case is when the application is installed by a user (either as drop in somewhere or installed in ~/bin or equivalent).

I can imagine someone installing the software with prefix=~/.local, but then it's entirely up to them to set up the paths. They can set sysconfdir=~/.config in such a case, for instance.

Do you think detecting the installation path to set the configuration files path is adequate ?

No, please don't try to outsmart the local system administrator or packager. Allow them to configure the path, and then stick to that.

Last edited by ayekat (2019-07-16 12:55:29)


{,META,RE}PKGBUILDSpacman-hacks (includes makemetapkg and remakepkg) │ dotfiles

Offline

Board footer

Powered by FluxBB