255

What is the difference between /etc/init/ and /etc/init.d/?

More generally, what meaning does the .d suffix convey to a directory?

muru
  • 197,895
  • 55
  • 485
  • 740

3 Answers3

253

/etc/init.d contains scripts used by the System V init tools (SysVinit). This is the traditional service management package for Linux, containing the init program (the first process that is run when the kernel has finished initializing¹) as well as some infrastructure to start and stop services and configure them. Specifically, files in /etc/init.d are shell scripts that respond to start, stop, restart, and (when supported) reload commands to manage a particular service. These scripts can be invoked directly or (most commonly) via some other trigger (typically the presence of a symbolic link in /etc/rc?.d/).

/etc/init contains configuration files used by Upstart. Upstart is a young service management package championed by Ubuntu. Files in /etc/init are configuration files telling Upstart how and when to start, stop, reload the configuration, or query the status of a service. As of lucid, Ubuntu is transitioning from SysVinit to Upstart, which explains why many services come with SysVinit scripts even though Upstart configuration files are preferred. In fact, the SysVinit scripts are processed by a compatibility layer in Upstart.

.d in directory names typically indicates a directory containing many configuration files or scripts for a particular situation (e.g. /etc/apt/sources.list.d contains files that are concatenated to make a virtual sources.list; /etc/network/if-up.d contains scripts that are executed when a network interface is activated). This structure is usually used when each entry in the directory is provided by a different source, so that each package can deposit its own plug-in without having to parse a single configuration file to reference itself. In this case, it just happens that “init” is a logical name for the directory, SysVinit came first and used init.d, and Upstart used plain init for a directory with a similar purpose (it would have been more “mainstream”, and perhaps less arrogant, if they'd used /etc/upstart.d instead).

¹ not counting initrd

  • 32
    esoteric historical note: the .d directories entered with System V. It was a puzzling notation then and ultimately probably one person's idea that got into the codebase and couldn't leave. For example, if you think that cat is a bad name for the task it performs, imagine how many files throughout the system you'd have to touch to change it. – msw Oct 02 '10 at 03:36
  • 1
    On systems, that have both directories, which of Upstart and SysVinit is used? Is there a way to check? – asheeshr Jun 20 '14 at 07:25
  • 5
    @AsheeshR Check whether there is a package called upstart or sysvinit. And in recent versions, it could be systemd as well (which didn't exist for Ubuntu back when I wrote my answer). It's whichever package provides /sbin/init (dpkg -S /sbin/init). – Gilles 'SO- stop being evil' Jun 20 '14 at 08:16
  • On the AWS Ubuntu instance I am using (from Bitnami), it's the upstart package that provides /sbin/init (ran dpkg -S /sbin/init). But Bitnami has placed its script in the /etc/init.d directory. Isn't this conflicting w/ your answer to @AsheeshR above? Thank you. – Sabuncu Dec 18 '14 at 21:09
  • 1
    @Sabuncu This is an example of “SysVinit scripts are processed by a compatibility layer in Upstart”. – Gilles 'SO- stop being evil' Dec 18 '14 at 21:34
  • Thank you so much Gilles for pointing me in the right direction. I am now researching the compatibility layer you mention. – Sabuncu Dec 19 '14 at 13:58
  • @Gilles so that was an example, but normally /etc/init.d/* are not used by systemd or upstart, are they? (just to be sure). I mean even if links in /etc/rc?.d/* exist, right? – Palo Apr 26 '16 at 05:23
  • @Palo Upstart itself doesn't use /etc/init.d/* or /etc/rc*.d/*, but there are an Upstart jobs /etc/init/rc.conf and /etc/init/rcS.conf that load them. – Gilles 'SO- stop being evil' Apr 26 '16 at 11:29
  • Update: 16.04 uses a new system. If you need to switch back to upstart, see http://notesofaprogrammer.blogspot.com/2016/09/running-upstart-on-ubuntu-1604-lts.html – woodvi Jan 28 '17 at 00:11
  • Now on xenial (16.04), systemd is now used. – ryeager Nov 20 '17 at 21:29
32

The ".d" is usually appended to a directory name to indicate that what used to be (or what could have been) handled by a single script or a single configuration file has been split into multiple files for the sake of convenience, but which should be included, or executed, together.

For example, /etc/apache/conf.d/ or /etc/apt/sources.d/

In cases where it's important which order they should be included/executed, the files in these directories sometimes start with a number, like "00-default" or "80-user" so that they execute in the right order.

In the case of /etc/init.d/ it sort of indicates that the scripts in "init.d" should all be executed. Nowadays, however, the init system of modern operating systems is a bit more involved than that, but the directory name is still there.

thomasrutter
  • 36,774
12

As you point out, the ".d" nomenclature is puzzling and strange, and doesn't really have any place in any modern system -- you'll notice that most modern services have tended to drop it.

The reason the directory is /etc/init and not /etc/upstart is because Upstart is the project name, the actual installed binary is still /sbin/init thus it would not make sense for its configuration to have a name that didn't match the binary.

Jorge Castro
  • 71,754
Scott
  • 1,324
  • 8
    This is wrong, see e.g. udev's rules.d, Xorg's relatively recent xorg.conf.d, not too old /etc/profile.d etc.. – Ruslan Jun 03 '14 at 10:20