Attach bash script to apache start
I have a bash script that I want to be executed before apache starts or restarts.
I want my bash script to be executed when apache starts during the bootup process 开发者_StackOverflow中文版and when I manually run "/etc/init.d/apache2 restart/start".
There is an init.d script "/etc/init.d/apache2" but I rather not touch that file.
Google is not very helpful :)
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.
精彩评论