Perl 为什么我对催眠的使用会对Heroku产生影响?
我正试图通过一个运行在上的应用程序获得hypnotoad。当进入它的运行循环时,有一些事情不会发生,导致它崩溃。我想我遗漏了一些简单的东西,但是Heroku文档没有帮助,我也无法从中获得好的错误消息 我从一个非常简单的应用程序开始,展示一些环境变量:Perl 为什么我对催眠的使用会对Heroku产生影响?,perl,heroku,mojo,hypnotoad,Perl,Heroku,Mojo,Hypnotoad,我正试图通过一个运行在上的应用程序获得hypnotoad。当进入它的运行循环时,有一些事情不会发生,导致它崩溃。我想我遗漏了一些简单的东西,但是Heroku文档没有帮助,我也无法从中获得好的错误消息 我从一个非常简单的应用程序开始,展示一些环境变量: #!/usr/bin/env perl # today use Mojolicious::Lite; get '/' => sub { my $c = shift; my $content = "Perl: $^X Pid
#!/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>
现在,我部署它时使用了:
使用默认的Perloku文件在运行:
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
尽管我看到一些参考资料说这是我应该得到的,但这并不是在运行hypnotoad。不过,该应用程序可以工作:
#!/bin/sh
/app/vendor/perl/bin/perl /app/vendor/perl-deps/bin/hypnotoad toady
我想我可以把Perloku文件改成hypnotoad:
% toady deploy heroku --create
% 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
hypnotoad启动并几乎立即关闭,没有其他日志消息:
#!/bin/sh
/app/vendor/perl/bin/perl /app/vendor/perl-deps/bin/hypnotoad -t toady
我可以将调用更改为使用-t
测试应用程序,以查看是否:
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
我收到了“一切看起来都很好”的信息,所以hypnotoad正在运行:
#!/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
我打开了Mojo调试日志记录,但除了我自己的语句之外,我看不到其他输出
$ 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.
我尝试了其他方法,比如让它加载一个我知道不存在的模块,然后在日志中得到预期的“找不到”错误
从heroku中的shell运行(heroku run bash
)没有启发性。mojo版本
的输出与我的本地机器上的输出相同:
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
我想我缺少了一些非常简单的东西,但同时,这些都不是为了方便调试而设计的
奥列格靠近了一点,但仍然有问题。我以前尝试过前台选项,但遇到了同样的问题,但没有提到它 如果我在前台启动hypnotoad,它会尝试绑定到一个地址。它无法绑定到端口80(或443)并崩溃,它可以侦听127.0.0.1:几乎,但看起来它无法完全侦听:
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
以下是一个未经授权的端口:
#!/bin/sh
perl /app/vendor/perl-deps/bin/hypnotoad -f mojocrashtest
这真的只是一个猜测,但heroku基础设施可能不希望运行程序终止?如果是这样,您可以尝试使用
--foreground
或-f
启动hypnotoad
另外,您可以尝试从应用程序内部进行一些日志记录,看看它是否运行过它。经过一些测试,我找到了在heroku上运行hypnotoad的方法 1。Perloku内容应该是这样的
heroku run bash
head /app/vendor/perl-deps/bin/hypnotoad
描述
首先,我们需要明确地调用perl。因为
#!/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猜测的hypnotoad的键-f
。否则heroku会认为你的应用程序意外完成
2。您应该在端口$ENV{port}上启动hypnotoad
对于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>
对于完整的应用程序,您可以在启动
处理程序中执行
3。heroku公开赛
这是Mojolicious::Lite应用程序的完整代码
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.
#/usr/bin/env perl
#今天
使用mojolicous::Lite;
插件配置=>{default=>{hypnotoad=>{listen=>[“http://*:$ENV{PORT}”]};
获取“/”=>sub{
我的$c=班次;
my$content=“Perl:$^X Pid:$$\n\n”;
foreach my$密钥(密钥%ENV){
下一步除非$key=~/Mojo | toad/i;
$content.=“$key$ENV{$key}\n”;
}
$c->stash(内容=>$content);
$c->render('index');
};
应用程序->启动;
__资料__
@@index.html.ep
%布局“默认”;
%标题“欢迎”;
欢迎使用Mojolicious实时web框架
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
$ 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
@@layouts/default.html.ep
heroku原木
$ heroku config:add BUILDPACK_URL=https://github.com/judofyr/perloku.git
2015-01-13T12:08:04.843204+00:00 heroku[web.1]:用命令`./Perloku启动进程`
2015-01-13T12:08:06.019070+00:00应用程序[web.1]:服务器可在http://127.0.0.1:13533.
2015-01-13T12:08:06.018899+00:00应用程序[web.1]:[Tue Jan 13 12:08:06 2015][info]收听“http://*:13533”。
2015-01-13T12:08:06.019035+00:00应用程序[web.1]:[2015年1月13日星期二12:08:06][info]3经理启动。
2015-01-13T12:08:06.055437+00:00应用程序[web.1]:[Tue Jan 13 12:08:06 2015][info]创建进程id文件“/app/hypnotoad.pid”。
2015-01-13T12:08:06.412283+00:00 heroku[web.1]:状态从启动更改为启动
2015-01-13T12:08:08.040072+00:00 heroku[路由器]:at=info method=GET path=“/”host=floating-temple-3676.herokuapp.com请求\u id=e9f9bb4d-f71f-4b4c-a129-70faf044c38b fwd=194“dyno=web.1 connect=3ms服务=34ms状态=200字节=586
2015-01-13T12:08:08.029819+00:00应用程序[web.1]:在/app/mojocrashtest第13行第39行的串联(.)或字符串中使用未初始化值。
2015-01-13T12:08:08.029836+00:00应用程序[web.1]:在/app/mojocrashtest第13行第39行的串联(.)或字符串中使用未初始化值。
2015-01-13T12:08:08.029839+00:00应用程序[web.1]:在/app/mojocrashtest第13行第39行的串联(.)或字符串中使用未初始化值。
2015-01-13T12:08:08.029842+00:00应用程序[web.1]:在/app/mojocrashtest第13行第39行的串联(.)或字符串中使用未初始化值。
我的应用程序的URL:顺便说一句,我没有使用
mojodeploy
,只是使用了git
,但是假设中缺少了一些内容
首先,创建一个新的heroku应用程序并记住该应用程序的名称:
$ mkdir testapp
$ cd testapp
$ git init
$ heroku git:remote -a vast-spire-6174
接下来,添加Perloku构建包:
#!/bin/sh
/app/vendor/perl/bin/perl /app/vendor/perl-deps/bin/hypnotoad -f myapp.pl
在Heroku上创建git回购和设置:
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
VERSION => '0.01',
PREREQ_PM => {'Mojolicious' => '5.72'},
test => {TESTS => 't/*.t'}
);
要使一切正常工作,您需要一个Perloku文件来在前台启动hypnotoad
。您必须明确指定perl
,因为hypnotoad
中的shebang行指的是perl
的临时位置,它是在构建时和不再存在的位置。请将myapp.pl更改为您命名的应用程序n
$ mojo generate lite_app
要安装所有内容,请使用标准的Makefile.PL.Spe
use strict;
use warnings;
use ExtUtils::MakeMaker;
WriteMakefile(
VERSION => '0.01',
PREREQ_PM => {'Mojolicious' => '5.72'},
test => {TESTS => 't/*.t'}
);
$ 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>
#!/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>
$ 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