111

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/?

102

/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.

27

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 :)

  • 2
    Hi @Joe Marty, This is exactly the problem I'm experimenting now. I have a service that relays on a "DISPLAY" environment variable that is not present when starting the daemon with "service myservice start" but present when starting it with "/etc/init.d/myservice start". Any idea on how to have this variable available? – frandevel Feb 11 '16 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.