Perl 在分叉进程中嵌入mojolicous::Server

Perl 在分叉进程中嵌入mojolicous::Server,perl,mojolicious,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::Se

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

我还没有发现文档/示例正在做我想做的事情。我敢肯定我只是找错地方了。

找到了答案。不管怎样,如果有人试图这样做,键入问题似乎总是埋下了修复的种子。(我的应用程序中仍然有一个错误,即停止测试,但我启动了服务器循环)

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

键入该问题似乎总是埋下了修复的种子。。。泰迪熊编程++
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();