OxDEAD Unicornz

Have you ever seen so many?

Don't Rely on Ubuntu 14.04 Service Autocomplition

It appears lot of my colleagues think they’ll get the name of any service in Ubuntu system autocompleted by typing service first_few_letters_of_service_name and pressing Tab button. When this does not work (and it does not work a lot) it creates a lot of confusion and rises lot of questions.

In Ubuntu 14.04, the script that handles completions for service command is /usr/share/bash-completion/bash_completion It looks for service names as files in /etc/rc.d/init.d, /etc/init.d, and in the output of systemctl list-units --full --all

Every package that provides a standard daemon using upstart is required to provide a symlink in /etc/init.d by Debian policy. If you have some homegrown upstart services having only configuration file in /etc/init you won’t have them in the autocompletion suggestions.

There are special upstart jobs in /etc/init that as well do not have a corresponding entry in /etc/init.d. These are an exception. From Debian Policy:

An exception to this rule is scripts or jobs provided by the init implementation itself; such jobs may be required for an implementation-specific equivalent of the /etc/rcS.d/ scripts and may not have a one-to-one correspondence with the init scripts.

These exceptions do not currently work with bash-completion. However, you can use start, stop, restart and reload directly without service, and autocompletion will work. For example, sudo start shut correctly autocompletes. But you shouldn’t normally need to directly call upstart jobs that do not have a corresponding init.d entry.

Source: Askubuntu, One more thread