Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'd like to have a single command that'll restart Apache on any *nix OS. Currently I'm working with Ubuntu, which has

  • /usr/sbin/apache2ctl
  • /usr/sbin/service
  • no apachectl
  • no httpd

and Scientific Linux CERN 5, which has

  • /usr/sbin/apachectl
  • /etc/init.d/httpd
  • no apache2ctl
  • no service

I'd like to avoid using a hack like which service 2>/dev/null || which /etc/init.d/httpd

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

apachectl / apache2ctl is the apache built in tool to control apache, it's probably the right tool to use in your case as it comes with apache it will be the some on all OS.
apachectl is normally for Apache 1.x and apache2ctl for Apache 2.x.
If SLC5 comes with Apache 2.x it's quite strange but you could run both apachectl and apache2ctl in your script.

share|improve this answer
add comment

You could use a script that checks which apachectl is installed and then run the appropriate one.

#!/bin/bash

if [ -e /usr/sbin/apacche2ctl ]
then
    /usr/sbin/apache2ctl restart
elif [ -e /usr/sbin/apachectl ]
then
    /usr/sbin/apachectl restart
else
    echo "No Apache control program found"
fi
share|improve this answer
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.