Why are init.d scripts in etc?
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.
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
.