Click to See Complete Forum and Search --> : Apache / MySQL on or off?


Norman Graham
02-24-2005, 04:58 AM
Hi LAMP fans

What BASH command(s) can I use to determine whether Apache and the MySQL server are started or not? The reason I ask is because I quickly got fed up typing in commands to start the two servers and wrote the commands into a BASH script, and very handy it is too. So now I have one script for starting these two racehorses and another one for putting them to bed again. However, what I would like to do is this:

#!/bin/bash
# Pseudo-code

if [Apache != "started" && MySQL != "started"]

/usr/local/apache2/bin/apachectl start

/path/to/mysql start etc.

else

shut down the whole lot etc.
So how can I determine whether they are on or off? If you tell me that, I can probably work out the rest myself. Btw - I know you can tell Apache and MySQL to start at boot, but that's not what I want.

If it helps: I'm running Apache 2.x and MySQL 4.1.9.

Thanks

Norm

bubblenut
02-24-2005, 06:12 AM
You can look for the daemon processes using ps -A (hyphen A tells ps to show all processes) and then greping the output for httpd or mysqld.

ps -A | grep httpd
ps -A | grep mysqld

Norman Graham
02-24-2005, 06:32 AM
Thanks, Bubblenut. I'll give that a shot and see how far I get.

Norm

id10t
02-24-2005, 09:57 AM
pidof mysqld

or

pidof apache