Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?
share|improve this question
2  
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

2 Answers 2

up vote 8 down vote accepted

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.

share|improve this answer
2  
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. –  phq 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 –  phq 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

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.

share|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 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 Apr 26 '11 at 21:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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