0

Am I being a curmudgeon, or should /etc/default be reserved to settings for the operating system?

I'm seeing systems show up with /etc/default/{company}-environment. The file is typically Tomcat data, but not always. I've also seen setup data for Mqueue.

One objection I've heard that makes sense on a technical level is that it does not allow applications to migrate to Containers. Beyond that, am I just carping?

I posted this question over in ServerFault, but it isn't getting any answers. What does the group assembled here think? I've looked in the local Confluence docs and it's been this way for like ten years. The technical curmudgeon in me just objects because /etc should not have anything but operating system components. I'd be interested in others' thoughts.

4
  • 1
    If you want answers here, you should migrate your question here — copy it here entirely, and delete the ServerFault question. Otherwise one or both will be closed (questions aren’t supposed to be posted on multiple SE sites). Would you care to explain why /etc wouldn’t be available in containers? Are you aware of the /etc description in the FHS? If configuration shouldn’t go in /etc, where would you consider it appropriate to place it? Commented Jun 11, 2024 at 21:04
  • This is one of those questions that straddles the line between administration (hence ServerFault) and programming. That being the case, I thought this group might have an interest as well. When in Rome. Commented Jun 11, 2024 at 21:32
  • 1
    The question of where apps' local environments should be set has been answered in different ways over time. The old school answer is /usr/local/. More recent practice is to use /opt/<company>. The /etc directory is so tightly tied to the OS it seems like a bad idea to use it for this kind of localization. Commented Jun 11, 2024 at 21:34
  • Finally, to your point about the link, I would say that proves my point -- everything there is for the OS, not the applications. In my understanding of Containers, the OS is inaccessible from the application, and in my old school view, /etc/ is part of the OS. Honestly, this is moot -- my employer was doing this long before I arrived, and they are unlikely to change. Just wanted to see what others did. Commented Jun 11, 2024 at 21:41

2 Answers 2

2

Your question seems pretty unclear, and maybe this is why nobody answered you yet.

However, you may consider the below statements coming only from my personal thoughts.

About the /etc/default folder and files.

  • The beauty of linux is that you may do pretty much anything you wish -> even adding some weird files in your /etc/ folder :)
  • AFAIK, the /etc/default folder is more related to some "defaults" configurations files (and env variables) that may be used by any apps requiring it. You may consider those files like "templates" usable by any apps,services, OS directives as "last resort" when they don't have any other custom confs available.
  • Most files in /etc/default (in an ubuntu setup), currently have the permissions root:root -rw-r--r--, meaning that everybody is able to read them (so there shall not be any serious "secrets" in those files), but only "root" has the right to modify them (proof that those templates are safe to use).
  • On my (ubuntu setup), the /etc/default shows some 'openvpn' and 'google chrome` related files. -> So it is NOT ONLY reserved to OS tasks.
  • For example, the /etc/default/useradd file defines some "Default values for useradd(8)", which may be (of course) overriden using some parameters from the useradd commandline (or some other conf files), but it is also smart enough to look for some default missing ones by looking into the related /etc/default file when necessary.

So basically, if you want to create a tool/app/software in linux, feel free to add a default template (configuration files and/or variables) in /etc/default/anyname, and then loading such variables into your shell script (if it is not specified by an input parameters) using the source directive (below just a dummy example):

#!/bin/bash
source /etc/default/anyname #"anyname" file having a DEF_VAR="radigris" in it.
any_var=""
if [ -z "$1" ]; then
    echo "param is unset, lets use the one from the template"
    any_var="${DEF_VAR}"
else
    echo "lets use the given parameter value"
    any_var="$1"
fi
echo "the final parameter value is: $any_var"

You also mentioned compatibility with containers

About containers compatibility, assuming you are talking about docker containers: I also do not see any problems or issues with it...

Lets assume you want to make an /etc/default/anyname available inside a docker container you may probably use this:

  • docker run -v /etc/default/anyname:/CONTAINER/PATH:ro -it anycontainer
  • or this docker run -v /etc/default/anyname:/etc/default/anyname:ro -it anycontainer(interesting: the 'ro' directive specifiable to keep the immutability aspect of the anyname file inside the container.
3
  • As I noted, I'm coming to this from an old school Unix viewpoint. Back in the day, /etc was part of the root file system. Things were placed there because they were always available from boot time, and didn't depend on subsequent file system mounts. That's less of an issue these days. This may be a simple preference issue, i.e., I just don't like it. Regarding Docker, you are correct, of course. It may even be a feature to have those variables set and immutable. Even so, we have a perfectly good solution in /opt. As a grumpy sysadmin I just don't like users mucking around in my /etc. Commented Jun 11, 2024 at 23:04
  • @ChrisK /etc still is in the root file system most of the time. It's not regular that anyone creates a different file system for /etc. As far as users mucking around in it concerned, there is data there such as shell init files and other things that users need to be able to read. Anything else such as the sudoer files aren't readable by anyone other than root. If this were really such a concern, then developers wouldn't have it that way. Commented Jun 11, 2024 at 23:44
  • Grudgingly accepting this as an answer I don't like along with that given by @Stephen Kitt below. "The beauty of linux is that you may do pretty much anything you wish -> even adding some weird files in your /etc/ folder :)" You say that as though it's a good thing. I think it illustrates the problem of giving developers root. But that's me being a curmudgeon! Commented Jun 12, 2024 at 15:50
1

At least on Linux distributions, the purpose of /etc/default is to store configuration files used by the general boot process, and in particular init scripts (in /etc/init.d). This allows system administrators (not general users) to change some settings used for system services without having to modify the init scripts themselves.

This is a perfectly valid use of /etc, at least in the context of Linux distributions applying the Filesystem Hierarchy Standard; the latter defines the purpose of /etc as follows:

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.

“A program” covers any application installed in the system, not just “operating system components” (whatever that means in the context of a distribution). Note however that regular users aren’t supposed to have to modify configuration files in /etc.

/etc/default is becoming less relevant as init scripts disappear in favour of systemd units in most distributions, but /etc still remains relevant for systemd: for example that’s where unit overrides go.

As far as containers are concerned, containers can also have /etc inside them, and configuration files from the host can be made available in a container by mounting them. In my experience though it’s not all that common to rely on these mechanisms to configure container-based workloads; if external configuration is required, it’s usually provided by some centralised mechanism made available through an external API of some kind.

2
  • I'm going to call this a valid answer even though I may not like it. For me anyway, the key point to this discussion is system administrators vs. non-root users. There is precedent for local configuration files, as in /etc/rc.local in the init style startup scripts, but I always saw even that as a place for system-wide settings. In my company developers have root on their development environments. If I were dictating, they would be putting their company-specific stuff in /opt/{company} rather than in /etc which I've always seen as the sysadmins' turf. Thanks for the discussion. Commented Jun 12, 2024 at 15:47
  • 1
    In my book, end-users’ settings go in their home directory, nowhere else ;-). Commented Jun 12, 2024 at 15:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.