[英]How can I display if a process is running on my web page?
I want to be able to display on my web page whether or not a process is running. 我希望能够在我的网页上显示某个进程是否正在运行。 Both run on the same system (Ubuntu server).
两者都在同一系统(Ubuntu服务器)上运行。
Basically, if something like the command ps -u game | 基本上,如果类似命令ps -u game | grep java returns something, I want the site to display something like "Game Server Online", else "Offline."
grep java返回了一些信息,我希望网站显示“ Game Server Online”之类的东西,否则显示“ Offline”。
I figure I could redirect the grep output to a file every 5 mins and have a script on the main page read the file content as a string to determine what to print. 我认为我可以每5分钟将grep输出重定向到一个文件,并在主页上有一个脚本以字符串形式读取文件内容以确定要打印的内容。 I feel as though there is be a much better way to do this, however.
我觉得似乎有更好的方法可以做到这一点。 What else could I do and which scripting language would be best for this task?
我还能做什么,哪种脚本语言最适合此任务?
If php is available, you could do something like this inline in your page: 如果可以使用php,则可以在页面中执行以下内联操作:
<?php
$output = shell_exec('ps -u game | grep java');
if ($output === "java something") {
echo "Server running"
} else {
echo "Server not running"
}
?>
what about a simple web service call? 一个简单的Web服务调用呢? calling a web service would ensure that both the server is up and the process is running.
调用Web服务将确保服务器已启动并且进程正在运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.