为什么我在Heroku上使用hypnotoad崩溃?

时间:2015-01-04 23:29:01

标签: perl heroku mojo hypnotoad

我试图通过Mojolicious::Lite使用Heroku运行Perloku应用来获取催眠效果。当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

尽管有一些参考文献我已经看到过这就是我应该得到的东西,但这并没有运行催眠术。但是,该应用程序可以运行:

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

这很有效,我得到了“一切看起来都很棒!”消息,所以催眠器正在运行:

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.

我认为我有一些非常简单的东西,但是同时,这些都不是为了便于调试而构建的。


奥列格稍近一点,但仍有问题。我之前尝试过前台选项并遇到同样的问题,但没有提到它。

如果我在前台启动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

3 个答案:

答案 0 :(得分:5)

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

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

答案 1 :(得分:4)

经过一些测试后,我找到了一种在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也可以。

然后我们需要密钥-f作为@moritz猜测的催眠。否则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

答案 2 :(得分:4)

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 repo并进行设置:

$ 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命令部署给我,所以可能有一些东西需要调查。但是,如果没有中介,提交和推送会更容易。