3

在一个小的 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
.

我还没有找到做我想做的事情的文档/示例。我确定我只是没有找对地方。

4

1 回答 1

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();

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

于 2012-09-01T16:18:25.440 回答