在分叉的进程中嵌入Mojolicious :: Server

时间:2012-09-01 15:59:11

标签: perl mojolicious

使用一个小的netflow收集器(比如ntop),我想在我的程序启动时生成一个Web服务器(不想强迫人们配置外部Web服务器)。我在弄清楚如何让我的应用程序在fork中启动时遇到了一些麻烦。这就是我正在做的事情:

#This is basically what the child process is doing.
#running this outside of my fork does the same thing.
use myApp;
use Mojo::Server;
use Mojo::Server::Daemon;
use Mojolicious::Commands;
my $daemon = Mojo::Server::Daemon->new( listen => ['http://*:5656'] );

Mojolicious::Commands->start_app('myApp');

myApp.pm包含

sub startup
{
    my $self = shift();

    my $r = $self->routes;

    $r->get('/') => sub {
        my $self = shift;

        $self->render( text => "Howdy!!" );
    };

}

当我运行这个时,我得到了以下内容。 。 。

usage: ./FlowTrack.pl COMMAND [OPTIONS]

Tip: CGI and PSGI environments can be automatically detected very often and
     work without commands.

These commands are currently available:
  cgi        Start application with CGI.
  cpanify    Upload distribution to CPAN.
  daemon     Start application with HTTP and WebSocket server.
  eval       Run code against application.
  generate   Generate files and directories from templates.
  get        Perform HTTP request.
.
.
etc
.

我没有找到我正在尝试做的文档/示例。我确定我只是没找对地方。

1 个答案:

答案 0 :(得分:4)

想出来。无论如何,如果其他人试图这样做,那么打字问题似乎总是会植入修复的种子。 (我的应用程序中仍有错误,即停止测试工作,但我已启动服务器循环)

use MyApp;
use Mojo::Server;
use Mojo::Server::Daemon;
use Mojolicious::Commands;

my $daemon = Mojo::Server::Daemon->new( app => MyApp, listen => ['http://*:5656'] );

$daemon->run();

最后找到了一个将应用程序放入守护程序新调用的示例。然后我意识到新的调用可能也没有启动循环,所以我在那里挖了一下。考虑删除问题,但我认为其他人可能会发现它有用。