Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I have a complex web application that contains a lot of dynamic Aliases. I created a shellscript that updates the .conf file(s) with these aliases. Is it possible to call this shellscript from within the Apache conf? So something like:

RunScript /etc/myapp/
Include /etc/myapp/*.conf

Or alternatively, is there a good way to add this script as a hook to the /etc/init.d/apache2 or /etc/init.d/httpd script? I am looking for a solution that works on both CentOS and Ubuntu. If I am totally approaching this the wrong way, any other suggestions are welcome as well.

share|improve this question
How often does your configuration get updated ? – Iain Aug 20 '11 at 13:55
up vote 1 down vote accepted

Sure, you can call it before starting the Apache in init script, something like this:

start() {
        echo -n $"Starting $prog: "
        check13 || exit 1
        . /etc/myapp/
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
share|improve this answer
Actually I ended up creating an additional init script which first runs the shell script and then calls the apache2 init script. – Jeroen Oct 4 '11 at 23:31

If the configuration needs to be updated regularly, I would be tempted to do this via a cron job and use the graceful option to when restarting apache. If you want to do this hourly/daily/weekly/monthly then you could put a script in the relevant /etc/cron.* directory and it will be run for you.


/etc/myapp/ && /sbin/service httpd graceful 
                            # change to /usr/sbin/service apache2 graceful 
                            # for ubuntu

would work.

If you need to do this when your system starts then edit /etc/crontab and add an @reboot entry

@reboot   root    /etc/myapp/ && /sbin/service httpd graceful

If apache hasn't already started it won't be started by the graceful option but your config files will be updated ready for apache to start. If apache is running it will be restarted.

share|improve this answer

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.