简体   繁体   English

如何从正在提供服务的网页上重新启动apache?

[英]How do I restart apache from a webpage apache is serving?

I have a script server side (both a shell and a python script) that can restart Apache and do some other cleanup I need. 我有一个脚本服务器端(shell和python脚本),可以重新启动Apache并执行我需要的其他一些清理工作。 However, I want to expose a webhook, so when my repository is updated, then Apache will be restarted. 但是,我想公开一个Webhook,因此在更新我的存储库时,Apache将重新启动。 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. 但是,我目前正在提供使用Apache重新启动Apache的URL,并且当脚本停止Apache或终止其进程时,脚本的其余部分将停止执行。

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. 我一直在网上寻找有关如何执行此操作的指南,尽管有数百万个用于重启Apache的脚本,但找不到有关如何设置Apache服务器以使脚本正确完成的指南。执行。

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 存储库系统将调用htpp://myserver.com/postwebhook之类的URL
  3. the postwebhook URL calls a script on the server that restarts apache postwebhook URL在服务器上调用一个脚本,该脚本重新启动apache
  4. the postwebhook URL returns a 200 status postwebhook URL返回200状态

Anybody have this working and can share how they set it up? 任何人都可以使用此功能,并且可以分享如何设置它?

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). 服务器关闭时,脚本无法继续运行(至少不能作为脚本运行,它可以启动另一个进程,更改其组,并且在重新启动时不会被Apache杀死,但是无论如何都无法返回结果)。

Here is a workaround: 这是一种解决方法:

  1. Create a script that can give you a process ID of the Apache web server. 创建一个脚本,该脚本可以为您提供Apache Web服务器的进程ID Call it from the client side and remember it. 从客户端调用它并记住它。
  2. Call the script that restarts Apache. 调用重新启动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. 最好使用Ajax,隐藏框架或其他合适的名称来调用它,以使用户看不到它。
  3. Wait some time and start calling the script that gives you a process ID again. 等待一段时间,然后开始调用再次为您提供进程ID的脚本。 Reaching a timeout while trying to call that script will mean that something went wrong and Apache failed to start after shutdown. 在尝试调用该脚本时达到超时将意味着出现问题,并且在关闭后Apache无法启动。 Reaching a timeout trying to get different process ID means server wasn't restarted at all. 尝试获取不同的进程ID达到超时意味着服务器根本没有重新启动。 Otherwise, process ID will be different (don't expect it to be greater or lower, however, it is very OS specific). 否则,进程ID将有所不同(不要期望它更大或更小,但是它是特定于操作系统的)。 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. 许多无线路由器在其Web界面中使用了类似的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM