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 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/updateconf.sh
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
add comment

2 Answers

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/updateconf.sh
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $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
add comment

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.

#!/bin/bash

/etc/myapp/updateconf.sh && /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/updateconf.sh && /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
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.