views:

25

answers:

1

I have a script server side (both a shell and a python script) that can restart Apache and do some other cleanup I need. However, I want to expose a webhook, so when my repository is updated, then Apache will be restarted. However, I am currently serving the URL that restarts Apache using Apache, and when the script stops Apache or kills its process, the rest of the script stops executing.

I've been looking all over the web for a guide on how to do this, and while there are a million scripts for restarting Apache, I can't find a guide on how to setup your Apache server so that the script will properly finish executing.

To illustrate what I'm looking for:

  1. i commit changes to my repository
  2. the repository system calls a url like htpp://myserver.com/postwebhook
  3. the postwebhook URL calls a script on the server that restarts apache
  4. the postwebhook URL returns a 200 status

Anybody have this working and can share how they set it up?

A: 

Script cannot continue while server is down (at least not as a script, it can start another process, change its group and not be killed by Apache on restart, but it won't be able to return result in any case).

Here is a workaround:

  1. Create a script that can give you a process ID of the Apache web server. Call it from the client side and remember it.
  2. Call the script that restarts Apache. Do not expect it to give you a result because it can't. It is better to call it using Ajax, hidden frame or whatever else is appropriate so that user doesn't see it.
  3. Wait some time and start calling the script that gives you a process ID again. Reaching a timeout while trying to call that script will mean that something went wrong and Apache failed to start after shutdown. Reaching a timeout trying to get different process ID means server wasn't restarted at all. Otherwise, process ID will be different (don't expect it to be greater or lower, however, it is very OS specific). By timeout I mean some period of time after which you stop trying. You have to try multiple times to call the script even though one of the attempts times out.

The similar approach is used by many wireless routers in their web interfaces.

Vlad Lazarenko