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

link|improve this question
feedback

2 Answers

up vote 1 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.

link|improve this answer
feedback

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 restrt
else
    echo "No Apache control program found"
fi
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.