Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

Is there any way to find the return value after I restart Apache Web server using the following command.

sudo /etc/init.d/apache2 restart

So that I can check whether Apache restart was successful or not.

share|improve this question

Three ways.

First, the variable $? holds the return code of the last shell command. So you can do

echo $?

and hope for a zero.

Second, you can scan the last few lines of the error_log and confirm that Apache started successfully. (tail -n 5 error_log) prints the last 5 lines; now just grep that output for a success string of your choosing.

tail -n 5 /my/path/error_log | grep 'resuming normal operations'

Third, you can list running processes and verify that the httpd process is running.

ps -u apacheuser -U apacheuser | grep apache2

where apacheuser is the user your server is configured to run as.

share|improve this answer
Isn't there any more specific command to get the return Value? What do you mean by the last shell command? – droidlabour Oct 10 '12 at 13:54
What kind of specificity are you looking for? Any process, when it exits, returns an integer as its exit code. Traditionally, zero means success, and any other value indicates an error. – Philip Oct 10 '12 at 14:00
It's exactly what it sounds like... the last command that was processed. If you open up and read /etc/init.d/apache2 and look at the 'restart' case, you can see exactly what it's doing. After a command runs, it updates the $? variable with a number, 0 meaning success and anything higher having custom meanings depending on the software. – Safado Oct 10 '12 at 14:01
Or if you can find someone that knows a little more about shell scripting you can edit the /etc/init.d/apache2 file to be a little more verbose during each step of the restart process – Safado Oct 10 '12 at 14:07

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.