Because of the way /etc/init.d/apache2
is written, you can't hijack it by putting your script ahead of apache2ctl
in the PATH
and modifying or renaming /usr/sbin/apache2ctl
would be more likely to get undone during an update. So that leaves you with a choice of modifying /etc/init.d/apache2
or magic.
It may be that the magic comes in the form of creating a symlink to your script in the appropriate /etc/rc?.d
directories with an appropriate prefix that would cause it to run before Apache. On my system, the name might be S88scriptname
, for example. You can make these links individually for each runlevel and manage them manually or, on systems such as Debian and Ubuntu that support it, you can model your script after /etc/init.d/skeleton
and set the options in the LSB header appropriately (particularly the X-Start-Before
keyword, perhaps) and use update-rc.d
to manage the rc?.d
symlinks for you.