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 PelletierAug 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.– ilkkachuAug 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.– ilkkachuAug 29, 2016 at 8:06
-
1Because when and how services start is system configuration.– OrangeDogAug 29, 2016 at 8:46
-
1For hysterical raisins.– TMNAug 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
/etc
at some point or another. At leastinit.d
is mostly scripts on modern systems. But it still isn't possible to have/etc
mounted readonly. 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. 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
/etc
might end cleaned up of non-config stuff.– GnPSep 1, 2016 at 18:56 -
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/rc
used 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/init
at 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/netstart
is a program; as is FreeBSD's/etc/ipfw.rules
. - So too are FreeBSD's
/etc/rc.suspend
and/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 systemrc
scripts.rc
scripts 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-bundles
are the between 60 and 70 that are needed before/usr
is mounted, including the services that mount and check/usr
if 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/usr
rather 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.
Digital UNIX quite sensibly placed the scripts under the /sbin/init.d
directory. And also HP-UX, according to the rosetta stone.