简体   繁体   English

启动和停止服务器脚本

[英]Starting and stopping server script

I've been building a performance test suite to exercise a server. 我一直在构建用于测试服务器的性能测试套件。 Right now I run this by hand but I want to automate it. 现在,我手动运行它,但是我想使其自动化。 On the target server I run a python script that logs server metrics and halts when I hit enter. 在目标服务器上,我运行一个python脚本,该脚本记录服务器指标并在按Enter键时暂停。 On the tester machine I run a bash script that iterates over JMeter tests, setting timestamps and naming logs and executing the tests. 在测试机上,我运行一个bash脚本,该脚本遍历JMeter测试,设置时间戳记和命名日志并执行测试。

I want to tie these together so that the bash script drives the whole process, but I am not sure how best to do this. 我想将它们绑在一起,以便bash脚本驱动整个过程,但是我不确定如何最好地做到这一点。 I can start my python script via ssh, but how to halt it when a test is done? 我可以通过ssh启动python脚本,但是如何在测试完成后将其暂停? If I can do it in ssh then I don't need to mess with existing configuration and that is a big win. 如果我可以在ssh中做到这一点,那么我就不需要弄乱现有的配置了,那是一个很大的胜利。 The python script is quite simple and I don't mind rewriting it if that helps. python脚本非常简单,如果有帮助,我不介意重写它。

The easiest solution is probably to make the Python script respond to signals. 最简单的解决方案可能是使Python脚本响应信号。 Of course, you can just SIGKILL the script if it doesn't require any cleanup, but having the script actually handle a shutdown request seems cleaner. 当然,如果不需要任何清除,您可以仅对脚本进行SIGKILL,但是让脚本实际处理关闭请求似乎更干净。 SIGHUP might be a popular choice. SIGHUP可能是一个流行的选择。 Docs here . 文档在这里

You can send a signal with the kill command so there is no problem sending the signal through ssh, provided you know the pid of the script. 您可以使用kill命令发送信号,因此只要知道脚本的pid,就可以通过ssh发送信号。 The usual solution to this problem is to put the pid in a file in /var/run when you start the script up. 解决此问题的通常方法是在启动脚本时将pid放在/ var / run中的文件中。 (If you've got a Debian/Ubuntu system, you'll probably find that you have the start-stop-daemon utility, which will do a lot of the grunt work here.) (如果您有Debian / Ubuntu系统,您可能会发现您有start-stop-daemon实用程序,它将在这里完成很多繁琐的工作。)

Another approach, which is a bit more code-intensive, is to create a fifo (named pipe) in some known location, and use it basically like you are currently using stdin: the server waits for input from the pipe, and when it gets something it recognizes as a command, it executes the command ("quit", for example). 另一种方法是代码密集型的,它是在某个已知的位置创建一个fifo(命名管道),并像使用当前的stdin一样使用它:服务器等待管道的输入以及何时获得输入它识别为命令,然后执行命令(例如“退出”)。 That might be overkill for your purpose, but it has the advantage of being a more articulated communications channel than a single hammer-hit. 对于您的目的而言,这可能有些过头,但它的优势是与单打相比,它是一种更加清晰的通信渠道。

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

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