I have recently migrated from Windows to Linux (xubuntu)

I am a developer and have installed everything I need, LAMP. In Windows I used to turn off all unnecessary services - I don't need the Apache or MySQL service running all the time. Whenever I needed MySQL I used to use:

net start mysql

How do I do the same in Linux?

  1. Disabling not-needed daemons from auto-starting?
  2. Starting them only when I need them?
  • 3
    I think you should include the exact version of ubuntu that you are using. New ubuntu versions use upstart, which has its own gotchas. – vtest Oct 27 '10 at 9:55
  • Edit:I am usning Xubuntu latest version 10.04, but id don't want to use and GUI for this, only from terminal. Looks like @prhq got something in his answer. What is upstart? – Aviv Oct 27 '10 at 13:30
  • Belongs elsewhere, either on Server Fault or Unix. Still useful though. – ripper234 Jun 11 '11 at 16:44

In most linux distributions you can manually start/stop services by (as root or using sudo) running the following commands:

# /etc/init.d/apache2 start
# /etc/init.d/mysqld start

# /etc/init.d/apache2 stop
# /etc/init.d/mysqld stop

Which services that are automatically started is controlled by file links in /etc/rc[runlevel].d/ . Find your current runlevel by using the command "runlevel" as root

# runlevel
N 2

Which here indicates runlevel 2 Now you just have to remove those files in /etc/rc2.d/ which you don't want started.

Removing apache and Mysql on a desktop is usually ok, but be aware of removing other services.

|improve this answer|||||
  • 3
    This is rather misleading, even if you said "most distributions". I would qualify your recipe as distro specific. – vtest Oct 27 '10 at 9:57
  • Which did you have in mind? I can only think of ArchLinux(but those users should already know what they are doing). Of course some distros have specific tools, but the above technique works on them as well. – hultqvist Oct 27 '10 at 10:47
  • Quite strange, i can see a file called S91apache2 in the /etc/rc2.d directory, i guess it starts the apache2 ... but i can't find any file regarding MySQL. Where can i learn about this auto-starting daemons? – Aviv Oct 27 '10 at 13:34
  • Then the mysql server might not be configured for automatic start. This site looks like having a good explanation: yolinux.com/TUTORIALS/LinuxTutorialInitProcess.html – hultqvist Oct 27 '10 at 17:44
  • Note that under *BSD and the Slackware tree, the directory is /etc/rc.d/. – new123456 Mar 28 '12 at 11:03

For Ubuntu versions that use systemd (15.04 and later) use:

systemctl disable service

This will do the job. It will disable the service and won't restart after a reboot. To temporarily enable simply start the service. Not enable.

To find the service name use

service --status-all

Other commands are:

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

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

systemctl restart service - Use it to restart a service

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

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

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

|improve this answer|||||
  • 2
    It's a pity it's not the accepted answer :). Thank's, I totally forgot about that command. – Nordes Apr 22 '19 at 0:59

Ubuntu 10.04 is in the middle of a transition between two service management systems: SysVinit (the traditional system, used by most Linux distributions) and Upstart (a newer system pushed by Ubuntu and becoming available in more and more distributions).

SysVinit service management scripts are in /etc/init.d. You can start the service with /etc/init.d/SERVICENAME start and stop it with /etc/init.d/SERVICENAME stop. Whether the service is started automatically on boot depends on the presence of symbolic links in /etc/rc?.d where ? is a digit from 2 to 5 (the runlevel). The easiest way to prevent a service from starting automatically on boot is to use update-rc.d SERVICENAME disable.

Upstart service management configuration files are in /etc/init. You can start the service with start SERVICENAME and stop it with stop SERVICENAME. The configuration file /etc/init/SERVICENAME.conf contains a line indicating when to start the service: start on …. An easy way of disabling these services is to change that line to start on never and (…). If you don't want to edit the file, you can also completely disable the service without confusing the packaging system by renaming it to not end in .conf.

dpkg-divert --add --local --divert /etc/init/foo.conf.disabled --rename /etc/init/foo.conf

As of Ubuntu 10.04, Apache comes with a SysVinit script and Mysql comes with an Upstart script.

|improve this answer|||||
  • Is editing the servicename.conf really the preferred way? Especially when updates can theoretically update those configuration files and override your changes – Masse Apr 21 '11 at 14:23
  • @Masse: It's not always the preferred way, but it has the advantage of always working. Some services read a file in /etc/default and have a START_FOO option there that you can turn off, but many expect to run if they're installed. Updates won't overwrite your changes without prompting since these are all conffiles. – Gilles 'SO- stop being evil' Apr 21 '11 at 19:07
  • Wow. This seems like a major step backwards. – Masse Apr 26 '11 at 20:43
  • @Masse: Conffiles are meant to be edited by the administrator. But if you don't want to do that, you can also use dpkg-divert to rename the service file. However if you do that you won't be able to start the service explicitly. – Gilles 'SO- stop being evil' Apr 26 '11 at 21:17

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.