2

I have an application with some cacheing backend and I want to clear the cacheing whenever the webserver is been restarted.

Is there a apache configuration directive or any other way to execute a shell script upon webserver (re)start?

Thanks, Phil

Adding some more information, as asked by some answers already:

  • Base system is ofc linux based, in this exact situation: CentOs
  • Modifying the startup script is unfortunately no option as pointed out by one of the comments already, due to it beeing not configuration file within the respective RPM packages and therefor beeing replaced by updates. Also I think modifying the startup script would be a bad thing in general
  • I see, that actually linking both "restarting the webserver" and "clearing my app cache" is not exactly what should be tied together. I will consider other alternatives
  • My situation is as follows: I can define how the virtual host config looks like, but I can not define how the rest of the servers configuration looks like.
  • The application is actually PHP based (and runs on the symfony framework). Symfony pre-compiles alot of stuff into dynamic php files from what it finds in the static configuration files. We deploy our apps via RPM and after deployment, an webserver restart is actually initiated already, so I thought it might make sense to tie the cache-cleanup to it. But I think after getting all your feedback, it looks like it is better to put the cache cleanup process into the installation process itself.

3 Answers 3

1

You haven't provided a lot of detail here, so it's hard to give a concrete answer, but I would suggest that your best option is to write a script which handles restarting apache, and clearing your cache. It would look something like this:

#!/bin/sh

# restart apache
/etc/init.d/httpd graceful

# whatever needs to be done to clear cache
rm -rf /my/cache/dir

Ramy suggests modifying the system startup script for Apache -- this is a bad idea! If and when you update Apache on your server, there is a good chance that your change will be lost.

Dirk suggests that what you are trying to do is probably misguided, and I think he's right. You haven't told us what platform you are running, but I can think of few situations where restarting your webserver and clearing a cache actually need to happen together.

Sign up to request clarification or add additional context in comments.

Comments

1

You can modify Startup script for the Apache Web Server in /etc/init.d/httpd and write your own syntax inside it.

chattr +i /etc/init.d/httpd

Comments

0

If you have (root) access to the server you could do this by shell scripts but I would consider if it is the best way of cache management to rely on apache restarts.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.