Search code examples
perlplack

How do I run Plack::Runner in the background?


I am trying to run a server with Plack::Runner. How do I run it in the background? I've tried the following:

my $runner = Plack::Runner->new;
$runner->parse_options(qw' --host 127.0.0.1 --port 90210 -D');
$runner->run($app);

It seems to ignore the -D. I've also tried '--daemon' and that doesn't work either.

Thanks!


Solution

  • What is $app?.

    my $runner = Plack::Runner->new;
    $runner->parse_options(qw' --host 127.0.0.1 --port 90210 -D');
    $runner->run("app.pm"); or "$app"
    

    app.pm is app file or you can try:

    my $app = sub {
        return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello World' ] ];
    };
    

    This works.