I keep reading/hearing that /etc is for system configuration files. Can someone explain/give me some intuition for why these scripts that start/stop/restart various programs are usually in /etc instead of /var or /usr or something similar?
-
Although the question could be slightly opinion oriented, I think the question can be answered with actual facts.Julie Pelletier– Julie Pelletier2016-08-29 04:13:05 +00:00Commented Aug 29, 2016 at 4:13
-
Are questions about historical reasons "opinion-based"? Looking back, there's likely some factual reason for why something happened. Even if it's just "because Mr. Grandhacker made it so", it's not up to the opinions of anyone answering the question now.ilkkachu– ilkkachu2016-08-29 08:01:26 +00:00Commented Aug 29, 2016 at 8:01
-
Except that the question said "why should they be" which is a trigger for opinion-based "colourful discussions". Edited a bit to make it less so. @Adam, do revert if you feel this is against your intention.ilkkachu– ilkkachu2016-08-29 08:06:05 +00:00Commented Aug 29, 2016 at 8:06
-
1Because when and how services start is system configuration.OrangeDog– OrangeDog2016-08-29 08:46:10 +00:00Commented Aug 29, 2016 at 8:46
-
1For hysterical raisins.TMN– TMN2016-08-29 14:26:02 +00:00Commented Aug 29, 2016 at 14:26
5 Answers
Early on (both historically, and in the process of booting...), /etc is a part of / (the first mounted filesystem), while /usr was not (until disks got large). /var holds temporary data, while these scripts are not temporary.
It's not that simple, but it started that way and there's little reason to rework the entire directory layout.
-
1As you say, it's not that simple. Various commercial UNIX systems had actual binary executables in
/etcat some point or another. At leastinit.dis mostly scripts on modern systems. But it still isn't possible to have/etcmounted readonly.Satō Katsura– Satō Katsura2016-08-29 08:03:41 +00:00Commented Aug 29, 2016 at 8:03 -
2@SatoKatsura: With the advent of compiled languages that feel like scripting languages I've started noticing some /etc scripts (even init scripts) being replaced by go programs - binary executables.slebetman– slebetman2016-08-29 08:22:38 +00:00Commented Aug 29, 2016 at 8:22
-
It's also interesting to note that modern sysVinit replacements do actually use simple configuration files instead of full fledged scripts, so
/etcmight end cleaned up of non-config stuff.GnP– GnP2016-09-01 18:56:30 +00:00Commented Sep 1, 2016 at 18:56 -
/tmpholds temporary data./varholds variable dataNeil McGuigan– Neil McGuigan2016-09-22 22:29:20 +00:00Commented Sep 22, 2016 at 22:29
Startup scripts are actually an important part of the system configuration.
Even though the boot-up process is much less customized than it was 15-30 years ago, and most of the startup configuration has been automated, all those administrative choices that determine the start-up sequence are still present in /etc.
This represents a very centralized way to maintain and backup the system's configuration. On most systems, backing up /etc is enough to allow a reinstallation of the whole system with ease. You simply do a full reinstall with the needed programs, and restore your /etc backup.
M. Dickey and M. Pelletier have both bought into the premises of the question. But the premises are wrong.
If you've read that "/etc is for system configuration files" then you've read something that doesn't paint the full picture for you. Look at the name. It's "et cetera". People have put everything bar the kitchen sink in there at one time or another.
/etc/rcused to be (and on some systems still is) the program run to start everything up.- The program image file for the first user process was
/etc/initat one point (in XENIX, for example, long before upstart was even an idea). /etc/profile,/etc/zprofile, and all of the rest are definitely scripts.- OpenBSD's
/etc/netstartis a program; as is FreeBSD's/etc/ipfw.rules. - So too are FreeBSD's
/etc/rc.suspendand/etc/rc.resume; and indeed/etc/rc.sendmail,/etc/rc.bsdextended, and/etc/rc.firewall.
Similarly, if you've read that "scripts that start/stop/restart various programs are usually in /etc instead of /var or /usr or something similar" then you've read something else that doesn't paint the full picture for you.
- FreeBSD/PC-BSD convention is to have a
/usr/local/etc/rc.d/directory for non-operating systemrcscripts.rcscripts for all sorts of things live there rather than under/etc. - You'll find daemontools-family people putting some service management things into
/var/sv,/var/service, and similar places. (My nosh toolset, for one example, provides almost a thousand service bundles in/var/sv. The only service bundles that go in/etc/service-bundlesare the between 60 and 70 that are needed before/usris mounted, including the services that mount and check/usrif necessary.) - systemd operating system conventions have some stuff living in
/etc/systemd, some stuff in/run/systemd, some stuff in/usr/lib/systemd, and (even though it's undocumented for inapplicable reasons) some stuff in/usr/local/lib/systemd. Again, the majority of "things for starting/stopping services" are to be found under/usrrather than under/etc.
You would do well to review the Filesystem Hierarchy Standard. It will explain (in detail) exactly why this is, but it also contains such information on many other paths you may be curious about.
The filesystem standard has been designed to be used by Unix distribution developers, package developers, and system implementors. However, it is primarily intended to be a reference and is not a tutorial on how to manage a Unix filesystem or directory hierarchy.
-
It does not explain the historic background.Thorbjørn Ravn Andersen– Thorbjørn Ravn Andersen2016-08-29 16:40:17 +00:00Commented Aug 29, 2016 at 16:40
Digital UNIX quite sensibly placed the scripts under the /sbin/init.d directory. And also HP-UX, according to the rosetta stone.