Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

3 Answers

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
add comment
up vote 1 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
add comment

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

share|improve this answer
1  
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
add comment

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.