What's the difference between "Service" and "/etc/init.d/"?

I've been managing server installations both on and off Ubuntu flavor for some time - I've become quite adjusted to /etc/init.d/ for restarting servcies. Now I get this message:

root@tatooine:~# /etc/init.d/mysql status
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql status

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the status(8) utility, e.g. status mysql
mysql start/running, process 14048

This seems to have been brought about in the latest LTS of Ubuntu - why? What's so bad about /etc/init.d/ and what/is there a difference between service and /etc/init.d/?


Solution 1:

/etc/init.d scripts are the old way of doing things. They come from the System V standard. However, those scripts are fired only in a particular sequence, so no real dependencies can be established.

Therefore, upstart has been developed with the intent to substitute all the /etc/init.d scripts with upstart scripts (in /etc/init).

service allows the smooth transition from /etc/init.d scripts to upstart scripts. In the future, when more and more scripts are transferred to upstart, service will still work because it finds both possibilities.

  • How to enable or disable services?

Solution 2:

Also check the man page for the service command: man service

service runs a script in a predictable environment (working directory is / and only 2 environment variables are set: LANG and TERM). It also adds the ability to do --full-restart. So to sum up:

  1. service may run scripts from either /etc/init or /etc/init.d (upstart or System V)
  2. service runs scripts in a predictable environment.

The "predictable environment" aspect can cause you problems if your script depends on an environment variable for some reason. There is probably a way to get around that, but I don't know what it is, and that's beyond the scope of this question :)