【问题标题】:Why is my use of hypnotoad crashing on Heroku?为什么我使用 hypnotoad 在 Heroku 上崩溃了?
【发布时间】:2015-03-02 12:25:09
【问题描述】:

我正在尝试使用在HerokuPerloku 上运行的Mojolicious::Lite 应用程序来获得催眠蟾蜍。当hypnotoad 进入导致它崩溃的运行循环时,有些事情不会发生。我想我遗漏了一些简单的东西,但是 Heroku 文档没有帮助,我也无法从中获得好的错误信息。

我从一个非常简单的应用程序开始,所以显示一些环境变量:

#!/usr/bin/env perl
# today
use Mojolicious::Lite;

get '/' => sub {
    my $c = shift;

    my $content = "Perl: $^X Pid: $$\n\n";
    foreach my $key ( keys %ENV ) {
        next unless $key =~ /Mojo|toad/i;
        $content .= "$key $ENV{$key}\n";
        }

    $c->stash( content => $content );

    $c->render('index');
    };

app->start;

__DATA__

@@ index.html.ep
% layout 'default';
% title 'Welcome';
<p>Welcome to the Mojolicious real-time web framework!</p>

<pre>
<%= $content %>
</pre>

@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
  <head><title><%= title %></title></head>
  <body><%= content %></body>
</html>

当我在本地运行时,我没有问题。我从环境变量中看到我的程序是在hypnotoad下运行的:

Welcome to the Mojolicious real-time web framework!

Perl: /Users/brian/Dropbox/bin/perls/perl5.20.0 Pid: 40006

HYPNOTOAD_PID 39981
MOJO_HELP 
HYPNOTOAD_TEST 
HYPNOTOAD_EXE /Users/brian/bin/perls/hypnotoad5.20.0
MOJO_REUSE 0.0.0.0:8080:6
HYPNOTOAD_REV 3
HYPNOTOAD_APP /Users/brian/Desktop/toady.d/toady
MOJO_MODE production
MOJO_HOME
HYPNOTOAD_STOP 
HYPNOTOAD_FOREGROUND

现在,我使用 Mojolicious::Command::deploy::heroku 部署它:

% toady deploy heroku --create

这是在https://frozen-brushlands-4002.herokuapp.com 运行,使用默认的 Perloku 文件:

#!/bin/sh
./toady daemon --listen http://*:$PORT --mode production

尽管我看到的一些参考资料表明这是我应该得到的,但它并没有运行 hypnotoad。但该应用程序有效:

Welcome to the Mojolicious real-time web framework!

Perl: /app/vendor/perl/bin/perl Pid: 3

MOJO_REUSE 0.0.0.0:12270:4
MOJO_HOME 
MOJO_HELP 
MOJO_MODE production
MOJO_EXE ./toady

我想我可以更改 Perloku 文件来启动 hypnotoad:

#!/bin/sh
/app/vendor/perl/bin/perl /app/vendor/perl-deps/bin/hypnotoad toady

hypnotoad 启动并几乎立即关闭,没有其他日志消息:

% heroku logs --app ...
2015-01-04T09:23:36.516864+00:00 heroku[web.1]: Starting process with command `./Perloku`
2015-01-04T09:23:38.321628+00:00 heroku[web.1]: State changed from starting to crashed

我可以更改调用以使用-t 来测试应用程序,看看是否:

#!/bin/sh
/app/vendor/perl/bin/perl /app/vendor/perl-deps/bin/hypnotoad -t toady

这行得通,我得到“一切看起来都不错!”消息,所以 hypnotoad 正在运行:

2015-01-04T09:36:36.955680+00:00 heroku[web.1]: Starting process with command `./Perloku`
2015-01-04T09:36:38.340717+00:00 app[web.1]: Everything looks good!
2015-01-04T09:36:39.085887+00:00 heroku[web.1]: State changed from starting to crashed

我打开了 Mojo 调试日志记录,但除了我自己的语句之外,我没有看到其他输出。

#!/usr/bin/env perl
use Mojolicious::Lite;

$|++;

my $log = app->log;

$log->level( 'debug' );

$log->debug( "INC: @INC" );

get '/' => sub {
    ...;
    };

$log->debug( "Right before start" );
my $app = app->start;
$log->debug( "Right after start" );

$app; # must return application object

我尝试了其他方法,例如让它加载一个我知道不存在的模块,并在日志中收到预期的“找不到”错误。

在 heroku (heroku run bash) 中从 shell 运行没有启发性。 mojo version 的输出和我本地机器上的一样:

$ perl vendor/perl-deps/bin/mojo version
CORE
  Perl        (v5.16.2, linux)
  Mojolicious (5.71, Tiger Face)

OPTIONAL
  EV 4.0+                 (n/a)
  IO::Socket::Socks 0.64+ (n/a)
  IO::Socket::SSL 1.84+   (n/a)
  Net::DNS::Native 0.15+  (n/a)

You might want to update your Mojolicious to 5.72.

我认为我缺少一些非常简单的东西,但与此同时,这些都不是为了便于调试而设计的。


Oleg 离得更近了一点,但还是有问题。我之前尝试过前台选项并遇到同样的问题但没有提及。

如果我在前台启动 hypnotoad,它会尝试绑定到一个地址。无法绑定80(或443)端口,崩溃了,可以监听127.0.0.1:差不多,但好像没能完全监听:

2015-01-13T11:47:54+00:00 heroku[slug-compiler]: Slug compilation started
2015-01-13T11:48:32+00:00 heroku[slug-compiler]: Slug compilation finished
2015-01-13T11:48:32.735095+00:
00 heroku[api]: Deploy dcab778 by ...
2015-01-13T11:48:32.735095+00:00 heroku[api]: Release v31 created by ...
2015-01-13T11:48:32.969489+00:00 heroku[web.1]: State changed from crashed to starting
2015-01-13T11:48:34.909134+00:00 heroku[web.1]: Starting process with command `./Perloku`
2015-01-13T11:48:36.045985+00:00 app[web.1]: Can't create listen socket: Permission denied at /app/vendor/perl-deps/lib/perl5/Mojo/IOLoop.pm line 120.
2015-01-13T11:48:36.920004+00:00 heroku[web.1]: Process exited with status 13
2015-01-13T11:48:36.932014+00:00 heroku[web.1]: State changed from starting to crashed

这里有一个非特权端口:

2015-01-13T11:39:10+00:00 heroku[slug-compiler]: Slug compilation started
2015-01-13T11:39:44+00:00 heroku[slug-compiler]: Slug compilation finished
2015-01-13T11:39:44.519679+00:00 heroku[api]: Deploy bbd1f68 by ...
2015-01-13T11:39:44.519679+00:00 heroku[api]: Release v29 created by ...
2015-01-13T11:39:44.811111+00:00 heroku[web.1]: State changed from crashed to starting
2015-01-13T11:39:47.382298+00:00 heroku[web.1]: Starting process with command `./Perloku`
2015-01-13T11:39:48.454706+00:00 app[web.1]: [Tue Jan 13 11:39:48 2015] [info] Listening at "http://*:8000".
2015-01-13T11:39:48.454733+00:00 app[web.1]: Server available at http://127.0.0.1:8000.
2015-01-13T11:39:48.454803+00:00 app[web.1]: [Tue Jan 13 11:39:48 2015] [info] Manager 3 started.
2015-01-13T11:39:48.480084+00:00 app[web.1]: [Tue Jan 13 11:39:48 2015] [info] Creating process id file "/app/hypnotoad.pid".
2015-01-13T11:40:47.703110+00:00 heroku[web.1]: Stopping process with SIGKILL
2015-01-13T11:40:47.702867+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2015-01-13T11:40:48.524470+00:00 heroku[web.1]: Process exited with status 137
2015-01-13T11:40:48.534002+00:00 heroku[web.1]: State changed from starting to crashed

【问题讨论】:

  • “mojo version”命令的输出是什么?
  • 我决定安装什么。我正在使用 5.71。
  • “mojo 版本”输出中有趣的部分是安装了哪些可选模块
  • 你怀疑有什么特别的吗?除了 Perl 5.16,它只是 Mojolicious 5.71。没有其他的。你用过 Heroku 吗?

标签: perl heroku mojo hypnotoad


【解决方案1】:

这真的只是一个疯狂的猜测,但也许 heroku 基础设施不希望 runner 终止?如果是这样,您可以尝试使用 --foreground-f 启动 hypnotoad。

此外,您可以尝试从应用程序内部进行一些日志记录,以查看它是否曾经运行过它。

【讨论】:

  • 你会注意到我确实做了记录。这是一个疯狂的猜测,根本没有帮助。我更喜欢不是猜测的答案。
  • 好的,以后我不会回答你,除非我确定它是正确的答案。
【解决方案2】:

经过一些测试,我找到了一种在 heroku 上运行 hypnotoad 的方法

1. Perloku 内容应如下所示

#!/bin/sh
perl /app/vendor/perl-deps/bin/hypnotoad -f mojocrashtest

说明

首先我们需要显式调用perl。因为

heroku run bash
head /app/vendor/perl-deps/bin/hypnotoad

表演

#!/tmp/perl/perls/perl-5.18.1/bin/perl

eval 'exec /tmp/perl/perls/perl-5.18.1/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

/tmp/perl/perls/perl-5.18.1/bin/perl 不存在的地方。所以,/app/vendor/perl-deps/bin/hypnotoad 不会启动,但perl /app/vendor/perl-deps/bin/hypnotoad 会好的。

然后我们需要@moritz 猜测的催眠蟾蜍的密钥-f。否则 heroku 会认为你的应用程序意外完成。

2。您应该在端口 $ENV{PORT}

上启动 hypnotoad

对于Mojolicious::Lite,你只需要在你的应用顶部写这样的东西:

plugin Config => {default => {hypnotoad => {listen => ["http://*:$ENV{PORT}"]}}};

对于完整的应用程序,您可以在 startup 处理程序中执行此操作。

3. heroku 打开


这是 Mojolicious::Lite 应用程序的完整代码
#!/usr/bin/env perl
# today
use Mojolicious::Lite;

plugin Config => {default => {hypnotoad => {listen => ["http://*:$ENV{PORT}"]}}};

get '/' => sub {
    my $c = shift;

    my $content = "Perl: $^X Pid: $$\n\n";
    foreach my $key ( keys %ENV ) {
        next unless $key =~ /Mojo|toad/i;
        $content .= "$key $ENV{$key}\n";
        }

    $c->stash( content => $content );

    $c->render('index');
    };

app->start;

__DATA__

@@ index.html.ep
% layout 'default';
% title 'Welcome';
<p>Welcome to the Mojolicious real-time web framework!</p>

<pre>
<%= $content %>
</pre>

@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
  <head><title><%= title %></title></head>
  <body><%= content %></body>
</html>

heroku 日志

2015-01-13T12:08:04.843204+00:00 heroku[web.1]: Starting process with command `./Perloku`
2015-01-13T12:08:06.019070+00:00 app[web.1]: Server available at http://127.0.0.1:13533.
2015-01-13T12:08:06.018899+00:00 app[web.1]: [Tue Jan 13 12:08:06 2015] [info] Listening at "http://*:13533".
2015-01-13T12:08:06.019035+00:00 app[web.1]: [Tue Jan 13 12:08:06 2015] [info] Manager 3 started.
2015-01-13T12:08:06.055437+00:00 app[web.1]: [Tue Jan 13 12:08:06 2015] [info] Creating process id file "/app/hypnotoad.pid".
2015-01-13T12:08:06.412283+00:00 heroku[web.1]: State changed from starting to up
2015-01-13T12:08:08.040072+00:00 heroku[router]: at=info method=GET path="/" host=floating-temple-3676.herokuapp.com request_id=e9f9bb4d-f71f-4b4c-a129-70faf044c38b fwd=194" dyno=web.1 connect=3ms service=34ms status=200 bytes=586
2015-01-13T12:08:08.029819+00:00 app[web.1]: Use of uninitialized value in concatenation (.) or string at /app/mojocrashtest line 13, <DATA> line 39.
2015-01-13T12:08:08.029836+00:00 app[web.1]: Use of uninitialized value in concatenation (.) or string at /app/mojocrashtest line 13, <DATA> line 39.
2015-01-13T12:08:08.029839+00:00 app[web.1]: Use of uninitialized value in concatenation (.) or string at /app/mojocrashtest line 13, <DATA> line 39.
2015-01-13T12:08:08.029842+00:00 app[web.1]: Use of uninitialized value in concatenation (.) or string at /app/mojocrashtest line 13, <DATA> line 39.

我的应用网址:http://floating-temple-3676.herokuapp.com/
顺便说一句,我没有使用mojo deploy,只是git

【讨论】:

  • 这对我不起作用。我已经用日志更新了帖子。你让你的工作了吗?你能显示 mojocrashtest 吗?
  • 好的,不通过 mojo 进行部署。 Mojolicious::Command::deploy::heroku 中一定有什么东西不能正常工作。这是所有这一切中缺少的一点点。
【解决方案3】:

Oleg answers the question,但假设中缺少一些部分。

首先,创建一个新的 Heroku 应用并记住应用的名称:

$ heroku create
 Creating vast-spire-6174... done, stack is cedar-14
 https://vast-spire-6174.herokuapp.com/ | https://git.heroku.com/vast-spire-6174.git

接下来,添加 Perloku 构建包:

$ heroku config:add BUILDPACK_URL=https://github.com/judofyr/perloku.git

在 Heroku 上创建 git 存储库和设置:

$ mkdir testapp
$ cd testapp
$ git init
$ heroku git:remote -a vast-spire-6174

要使一切正常运行,您需要一个 Perloku 文件以在前台启动 hypnotoad。您必须明确指定perl,因为hypnotoad 中的shebang 行指的是perl 在构建时的临时位置,并且不再存在。将 myapp.pl 更改为您为应用程序命名的任何名称。

#!/bin/sh
/app/vendor/perl/bin/perl /app/vendor/perl-deps/bin/hypnotoad -f myapp.pl

要安装所有内容,请使用标准的 Makefile.PL。将 Mojolicious 指定为先决条件之一:

use strict;
use warnings;

use ExtUtils::MakeMaker;

WriteMakefile(
  VERSION   => '0.01',
  PREREQ_PM => {'Mojolicious' => '5.72'},
  test      => {TESTS => 't/*.t'}
);

最后是应用程序本身,您可以使用mojo 创建它(调用的是myapp.ppl

$ mojo generate lite_app

这是生成的源代码:

#!/usr/bin/env perl
use Mojolicious::Lite;

# Documentation browser under "/perldoc"
plugin 'PODRenderer';

get '/' => sub {
  my $c = shift;
  $c->render('index');
};

app->start;
__DATA__

@@ index.html.ep
% layout 'default';
% title 'Welcome';
Welcome to the Mojolicious real-time web framework!

@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
  <head><title><%= title %></title></head>
  <body><%= content %></body>
</html>

你必须修改基本程序,因为 hypnotoad 需要一些配置(默认服务器不需要):

#!/usr/bin/env perl
use Mojolicious::Lite;

# Documentation browser under "/perldoc"
plugin 'PODRenderer';

plugin Config => {
    default => {
        hypnotoad => {
            listen => ["http://*:$ENV{PORT}"]
            }
        }
    };

get '/' => sub {
  my $c = shift;
  $c->render('index');
};

app->start;
__DATA__

@@ index.html.ep
% layout 'default';
% title 'Welcome';
Welcome to the Mojolicious real-time web framework!

@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
  <head><title><%= title %></title></head>
  <body><%= content %></body>
</html>

获得所有文件后,提交它们,然后推送到 heroku 分支。

$ git add .
$ git commit -am "make it better"
$ git push heroku master

当你按下时,一个钩子会启动一切。

Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 1.14 KiB | 0 bytes/s, done.
Total 7 (delta 0), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Fetching custom git buildpack... done
remote: -----> Perloku app detected
remote: -----> Vendoring Perl
remote:        Using Perl 5.18.1
remote: -----> Installing dependencies
remote:        --> Working on /tmp/build_a73f24f0619fa2ab299586098c5e8daf
remote:        Configuring /tmp/build_a73f24f0619fa2ab299586098c5e8daf ... OK
remote:        ==> Found dependencies: Mojolicious
remote:        --> Working on Mojolicious
remote:        Fetching http://www.cpan.org/authors/id/S/SR/SRI/Mojolicious-5.72.tar.gz ... OK
remote:        Configuring Mojolicious-5.72 ... OK
remote:        ==> Found dependencies: IO::Socket::IP
remote:        --> Working on IO::Socket::IP
remote:        Fetching http://www.cpan.org/authors/id/P/PE/PEVANS/IO-Socket-IP-0.36.tar.gz ... OK
remote:        Configuring IO-Socket-IP-0.36 ... OK
remote:        Building IO-Socket-IP-0.36 ... OK
remote:        Successfully installed IO-Socket-IP-0.36
remote:        Building Mojolicious-5.72 ... OK
remote:        Successfully installed Mojolicious-5.72
remote:        <== Installed dependencies for /tmp/build_a73f24f0619fa2ab299586098c5e8daf. Finishing.
remote:        2 distributions installed
remote:        Dependencies installed
remote: -----> Discovering process types
remote:        Procfile declares types   -> (none)
remote:        Default types for Perloku -> web
remote:
remote: -----> Compressing... done, 14.1MB
remote: -----> Launching... done, v5
remote:        https://vast-spire-6174.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/vast-spire-6174.git
 * [new branch]      master -> master

您的应用程序的 URL 显示在输出的末尾。

为什么在我不知道之前这对我有用。我让 mojo 命令为我部署,所以那里可能有一些需要调查的东西。但是,在没有中介的情况下提交和推送会更容易一些。

【讨论】:

  • 那么 $PORT 怎么样?您不需要指定 hypnotoad 应该监听哪个端口吗?
  • 啊,是的,我会解决的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-22
  • 2023-03-29
  • 1970-01-01
  • 2020-08-15
  • 2013-01-17
相关资源
最近更新 更多