Run shell script from Apache conf or at Apache (re)start

Solution 1:

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
}

Solution 2:

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.