追踪“工作”在 mod_perl 下使用 Perl
我已经在 mod_perl 下运行了这个项目,显示了主机上的一些信息。此页面上有一个带有下拉列表的文本框,允许用户 ping/nslookup/traceroute 主机。输出像 tail -f
一样显示在文本框中。
它在 CGI 下工作得很好。当用户请求 ping 时,它会对服务器进行 AJAX 调用,本质上是启动 ping 并将输出发送到临时文件。然后后续的 ajax 调用将“拖尾”该文件,以便更新输出,直到 ping 完成。作业完成后,临时文件将被删除。
然而,在 mod_perl 下,无论我做什么,我都可以阻止它创建僵尸进程。我已经尝试了一切,双重分叉,使用IPC::Run
等。最后,在mod_perl下不鼓励系统调用。
所以我的问题是,也许有更好的方法来做到这一点?是否有一个 CPAN 模块可用于创建在 mod_perl 下工作的命令行作业和尾部输出?我只是在寻找一些建议。
我知道我可能可以创建某种“工作”守护进程,我用它来发送详细信息并从中获取更新。它将运行命令并跟踪它们的状态等。但是有更简单的方法吗?
提前致谢。
I've got this project running under mod_perl shows some information on a host. On this page is a text box with a dropdown that allows users to ping/nslookup/traceroute the host. The output is shown in the text box like a tail -f
.
It works great under CGI. When the user requests a ping it would make an AJAX call to the server, where it essentially starts the ping with the output going to a temp file. Then subsequent ajax calls would 'tail' the file so that the output was updated until the ping finished. Once the job finished, the temp file would be removed.
However, under mod_perl no matter what I do I can's stop it from creating zombie processes. I've tried everything, double forking, using IPC::Run
etc. In the end, system calls are not encouraged under mod_perl.
So my question is, maybe there's a better way to do this? Is there a CPAN module available for creating command line jobs and tailing output that will work under mod_perl? I'm just looking for some suggestions.
I know I could probably create some sort of 'job' daemon that I signal with details and get updates from. It would run the commands and keep track of their status etc. But is there a simpler way?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这方面的时间很短,并且对 CPAN 没有什么运气,所以我将在这里提供我的解决方案(我可能重新发明了轮子)。我必须立即完成一些事情。
在本例中我将使用 ping。
当用户请求 ping 时,AJAX 脚本会在数据库中创建一条记录,其中包含 ping 的详细信息(主机、间隔、计数等)。该记录有一个自动递增的 ID 字段。然后,它向作业守护进程发送 SIGHUP,该守护进程只是一个守护进程化的 Perl 脚本。
该作业守护进程接收 SIGHUP,在数据库中查找新作业并处理每个作业。当它获得新作业时,它会分叉,将 PID 和“运行”状态写入数据库记录,根据唯一的作业 ID 打开 stdout/stderr 文件,并使用
IPC::Run
来引导STDOUT/STDERR 到这些文件。作业守护进程会跟踪分叉作业,如果它们运行时间过长,就会终止它们等。
为了跟踪输出,AJAX 脚本将作业 ID 发送回浏览器。然后,在 Javascript 计时器上,调用 AJAX 脚本,该脚本基本上通过数据库记录检查作业的状态并跟踪文件。
当 ping 完成时,作业守护程序将记录状态设置为“完成”。 AJAX 脚本在其常规状态检查中对此进行检查。
我这样做的原因之一是 AJAX 脚本和作业守护进程通过身份验证手段(数据库)进行通信。
I had a short timeframe on this one and had no luck with CPAN, so I'll provide my solution here (I probably re-invented the wheel). I had to get something done right away.
I'll use ping in this example.
When ping is requested by the user, the AJAX script creates a record in a database with the details of the ping (host, interval, count etc.). The record has an auto-incrementing ID field. It then sends a SIGHUP to to a job daemon, which is just a daemonised perl script.
This job daemon receives the SIGHUP, looks for new jobs in the database and processes each one. When it gets a new job, it forks, writes the PID and 'running' status to the DB record, opens up stdout/stderr files based on the unique job ID and uses
IPC::Run
to direct STDOUT/STDERR to these files.The job daemon keeps track of the forked jobs, killing them if they run too long etc.
To tail the output, the AJAX script send back the job ID to the browser. Then on a Javascript timer, the AJAX script is called which basically checks the status of the job via the database record and tails the files.
When the ping finishes, the job daemon sets the record status to 'done'. The AJAX script checks for this on it's regular status checks.
One of the reasons I did it this way is that the AJAX script and the job daemon talk through and authenticated means (the DB).