Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a laptop. I use it for web+email a lot, and then some days for web development. Using it for the latter, I need apache2 and mysql server running, but normally I do not.

I'd like a normal boot to NOT start apache and mysql, to conserve power, reduce boot times etc. but then to be able to start these services when needed.

In the olden days I might have used runlevels for this, but that's a bit old skool now, as I understand. What's the best way to achieve this in Precise?

share|improve this question

To stop mysql from starting at boot:

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

To stop apache2 from starting at boot:

sudo update-rc.d apache2 disable 2

Whenever you need to start mysql or apache2 all you need to do is to start the service yourself (and you can also stop both manually).

You can use

sudo apache2ctl {start|stop|restart}

for that and

sudo service mysql {start|stop}

for mysql.

share|improve this answer
comment: I did the 1st 2 commands from memory (if they are wrong don't yell ;) but feel free to edit my answer). – Rinzwind Jul 18 '12 at 18:37
yep it's apache2ctl nowadays (too small an edit to be allowed). Thanks: the first two are v. useful. The old runlevels were quite handy for this sort of thing. I sort of expected there to be an upstart way to trigger both apps to start (mysql needs to go before apache, ideally). – artfulrobot Jul 18 '12 at 19:05
Your apache app breaking when mysql does not precede it is a fail BTW. Think about a datacenter power outtage.. the DB server might take a few more minutes than the webservers to come back up. Degrade gracefully FTW. – SpamapS Jul 29 '12 at 7:01
up vote 2 down vote accepted

A way to do it with good ol' runlevels:

MySQL now uses an upstart script, but inside that it's still talking about runlevels. Edit /etc/init/mysql.conf and change lines as in this diff:

-start on runlevel [2345]
-stop on starting rc RUNLEVEL=[016]
+start on runlevel [345]
+stop on starting rc RUNLEVEL=[0126]

Apache2 still uses runlevel rc.N.d sym links:

sudo update-rc.d -f apache2 remove 
sudo update-rc.d apache2  start 91 3 4 5 . stop 09 0 1 6 .

Then on a normal boot (runlevel 2), they won't be started, and when you do sudo telinit 3, they will.

share|improve this answer
Why not add 2 as a stop to get apache2 stopped when going back to runlevel 2? – Sylwester Jul 13 '14 at 15:31
@Sylwester Yeah, you're right, just an oversight in my answer. Thanks. – artfulrobot Jul 13 '14 at 18:49

you can use programs given in the link look here and here

share|improve this answer
Please refrain from dumping links. It does not help when people search this website and links tend to rot. – Rinzwind Jul 18 '12 at 18:35

Your Answer


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.