7 Answers
7

There are services that can be enabled/disabled using the GUI (Like the startup application) and then other ways of doing the same through the terminal.

For the Terminal you have several options. Open a terminal (Type "terminal" in the dash for example and open it) and keep on reading:

Enabling / Disabling a service

To toggle a service from starting or stopping permanently you would need to:

echo manual | sudo tee /etc/init/SERVICE.override

where the stanza manual will stop Upstart from automatically loading the service on next boot. Any service with the .override ending will take precedence over the original service file. You will only be able to start the service manually afterwards. If you do not want this then simply delete the .override. For example:

echo manual | sudo tee /etc/init/mysql.override

Will put the MySQL service into manual mode. If you do not want this, afterwards you can simply do

sudo rm /etc/init/mysql.override

and Reboot for the service to start automatically again. Of course to enable a service, the most common way is by installing it. If you install Apache, Nginx, MySQL or others, they automatically start upon finishing installation and will start every time the computer boots. Disabling as mentioned above will make state of the service manual.

Temporary enabling/disabling services

To stop and start services temporarily (Does not enable / disable them for future boots), you can type service SERVICE_NAME. For example:

sudo service apache2 stop (Will STOP the Apache service until Reboot or until you start it again).

sudo service apache2 start (Will START the Apache service assuming it was stopped before.).

service apache2 status (Will tell you the STATUS of the service, if it is either enabled/running of disabled/NOT running.).

sudo service apache2 restart (Will RESTART the service. This is most commonly used when you have changed, a config file. For example in this case, if you have changed either a PHP configuration or a Apache configuration. Restart will save you from having to stop/start with 2 command lines)

service apache2 (In this case, since you did not mention the ACTION to execute for the service, so it will show you all options available for that specific service.)

This of course can vary depending on the service, for example, with MySQL it would only mention that it is missing a parameter. For other services like networking service it would mention the small list of all options available.

UPSTART

If we would wanted to use the official Upstart way (Note that, for the moment, not all services have been converted to Upstart), we could use the following commands:

status SERVICE - This will tell us if a converted service is running or not. Note that this is deprecated in favor of start, stop, status & restart. It will also tell us if a service was not yet been converted to upstart:

A converted service would typically output the current status (Starting, Running, Stopping...) and process ID. A non converted service would give an error about an unknown job.

Some shortcuts may only work with the service command above but not with the commands below unless they are 100% converted to upstart services:

START - sudo start mysql

STOP - sudo stop mysql

RESTART - sudo restart mysql

STATUS - sudo status smbd

SYSTEMD

Starting with Ubuntu 15.04, Upstart will be deprecated in favor of Systemd. With Systemd to manage the services we can do the following:

systemctl start SERVICE.service - Use it to start a service. Does not persist after reboot

systemctl stop SERVICE.service - Use it to stop a service. Does not persist after reboot

systemctl restart SERVICE.service - Use it to restart a service

systemctl reload SERVICE.service - If the service supports it, it will reload the config files related to it without interrupting any process that is using the service.

systemctl status SERVICE.service - Shows the status of a serviceTells whether a service is currently running.

systemctl enable SERVICE.service - Turns the service on, on the next reboot or on the next start event. It persists after reboot.

systemctl disable SERVICE.service - Turns the service off on the next reboot or on the next stop event. It persists after reboot.

systemctl is-enabled SERVICE.service - Check if a service is currently configured to start or not on the next reboot.

systemctl is-active SERVICE.service - Check if a service is currently active.

systemctl show SERVICE.service - Show all the information about the service.

I just installed 14.04 and this works for dovecot but not postgres, postfix, or clamd.
–
Joe MurrayNov 10 '14 at 4:02

@JoeMurray Thanks for the feedback. Let me get back to you with an answer when I get home. For what I remember, postgres for example can have multiple instances on Ubuntu, so it needs to be managed in another way.
–
Luis Alvarado♦Nov 10 '14 at 12:54

1

Ok I have tested postgres and postfix at least. Both work correctly ether using the old /etc/init.d path or the service command. Both do not work when using the upstart shortcuts (start,stop,restart,status) so I made a update on that part. You should at least be able to manage them using the other 2 ways.
–
Luis Alvarado♦Nov 10 '14 at 13:19

Upstart in the future? You just said it would be replaced with Systemd in the future...
–
HitechcomputergeekMar 24 at 14:34

Currently there are actually 2 different ways for software to be started as a service in Ubuntu. A service is defined here as a program run by the system in the background, as opposed to one started and run directly by the user.

The traditional way to start services in Linux was to place a script in /etc/init.d, and then use the update-rc.d command (or in RedHat based distros, chkconfig) to enable/disable it. This command, btw, uses some mildly complicated logic to create symlinks in /etc/rc#.d, that control the order of starting services. If you run ls /etc/rc2.d you can see the order that services will be killed (K##xxxx) and started (S##xxxx).

The issue with that was that when booting the system, everything had to be done in serial, one thing after another, making system boot times really slow. Attempts were made to parallelize this, but they were haphazard and hard to take full advantage of. This was the main reason that Upstart was created.

Upstart uses job definition files in /etc/init to define on what events a service should be started. So, while the system is booting, upstart processes various events, and then can start multiple services in parallel. This allows them to fully utilize the resources of the system, for instance, by starting a disk-bound service up while another CPU-bound service runs, or while the network is waiting for a dynamic IP address to be assigned.

You can see all of the upstart job files by running ls /etc/init/*.conf

Let me just stop here and say that if you don't know what a service is, or what it does, DO NOT disable it!

Not all services have been converted to upstart. While working on the server team at Canonical for the past few months, I've worked on a number of converted job files, and the nicest part is that it allows one to get rid of all the script "magic" and just put in a few commands here and there to define exactly how to start the service, and nothing more. But for now, only a handful of traditional network services, like squid and samba, have been converted.

In order to figure out if a service is upstart based, you can run the status command:

status servicename

If its an upstart job, it will show this:

$ status statd
statd start/running, process 942

But if its not, you'll see something more like this:

$ status apache2
status: Unknown job: apache2

In this case, apache2 has not been converted to upstart. So, to disable apache2 you just run

sudo update-rc.d apache2 disable
sudo service apache2 stop

Upstart job definitions do not have an update-rc.d command. To disable the job, you need to edit the job file directly to disable it. There are two ways to do this.

If you want to still be able to manually start it, then you need to comment out the 'start on' condition. Say you want to install samba, but not have it start automatically.. here is its job file (in natty):

To disable it, you can just put a # in front of the 'start on local-filesystems'. Note that while it won't start back up on boot, you still need to stop it this time with

sudo service smbd stop

If, however, you never want it to start, I'd suggest actually removing the package. If, however, you want it installed, but not startable, you can also do:

mv /etc/init/smbd.conf /etc/init/smbd.conf.disabled

Starting with the version of upstart that will be in 11.04, there is a new keyword that disables the 'start on' and 'stop on' stanzas, it is 'manual'. So another way to disable the service as of 11.04 is to do:

Great, thanks. Finally figured out how to stop a couple of "mystery services", and enough that I can start experimenting with services on my own.
–
j-g-faustusJan 6 '11 at 21:20

17

Looks like 11.04 has override too. So echo manual >> /etc/init/<service>.override is prefered as it leaves the original .conf filke intact. Anyway, its still a shame that such a basic enable/disable took 3 years to develop, and theres no GUI for that.
–
MestreLionMay 27 '11 at 3:09

I assume that the *.override files are appended to *.conf files for computing the result but this is not documented anywhere. Another interpretation would be that *.override replaces the contents of *.conf but would break the exec and friends in the *.conf file.
–
Mikko RantalainenFeb 7 '13 at 13:04

2

seems to much mor ehandle the original topic than the answer that has been tagged as the defintive answer by the original question poster. Thanks! :)
–
HenningApr 6 '14 at 11:11

For those of us who run Ubuntu over ssh, I think the nicest option is rcconf - a text based program:

sudo apt-get install rcconf
sudo rcconf

Navigate with tab and arrow keys, press spacebar to enable/disable. Changes are persistent across restarts.

Screenshot borrowed from this blogpost, which also shows sysv-rc-conf - a similar tool that also lets you set the runlevel. (For those who happen to care enough about runlevels to wish to change them :)

Unfortunately, rcconf doesn't work with upstart (services listed in /etc/init/*), just with the traditional mechanism (ls -l /etc/init.d/* - the ones that are not symbolic links).

Fortunately, many of the services that are relevant when ssh-ing in to a server (Apache, Tomcat, mdadm, boinc-client...) haven't been moved to upstart yet.

Unfortunately, no. But it has worked for all the cases I have wanted to change - the upstart jobs seems to be mostly things I never want to disable - hardware clock, log daemon, network etc. (on Ubuntu server, at least). But it's something to be aware of (I wasn't :), I've updated the post.
–
j-g-faustusJan 6 '11 at 20:59

Unfortunately mysql was converted to upstart. And thats a service i only use when im doing some project.
–
MestreLionMay 27 '11 at 3:12

There's a bug with rcconf on Ubuntu 12.04 that prevents the program from starting. To solve the issue you need to install the dialog package.
–
deviusJun 2 '12 at 22:08

@devius you can also work around that bug using sudo ln -s /bin/whiptail /usr/bin/whiptail
–
MahnSep 11 '13 at 18:55

Editing the existing upstart configuration file (as described above) is not such a good idea. An updated package could provide an updated config, and you'd had to repeat your changes over and over.

By taking a look at man 5 init one will find a more appropriate solution: using an override config. Short example: Say we have a service called "foobar", so there would be a file called /etc/init/foobar.conf with its upstart configuration. Now you don't want to remove that file, nor to modify it -- but neither you want this service to run? So place an override file next to it: /etc/init/foobar.override, containing (optionally the header with the description and) instead the start on / stop on lines you place a line with one word: manual. This way you tell upstart to basically use the foobar.conf, but override the startup definition to only start that service when manually enforced (via service foobar start in our example).