Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Foreman导出的Upstart脚本工作不正常,重新启动过快_Ruby On Rails_Upstart_Foreman - Fatal编程技术网

Ruby on rails Foreman导出的Upstart脚本工作不正常,重新启动过快

Ruby on rails Foreman导出的Upstart脚本工作不正常,重新启动过快,ruby-on-rails,upstart,foreman,Ruby On Rails,Upstart,Foreman,我能找到的唯一错误是查看dmesg [ 603.598951] init: thx4-web-1 main process ended, respawning [ 603.607935] init: thx4-web-1 main process (3901) terminated with status 127 [ 603.607988] init: thx4-web-1 main process ended, respawning [ 603.616866] init: thx4-w

我能找到的唯一错误是查看
dmesg

[  603.598951] init: thx4-web-1 main process ended, respawning
[  603.607935] init: thx4-web-1 main process (3901) terminated with status 127
[  603.607988] init: thx4-web-1 main process ended, respawning
[  603.616866] init: thx4-web-1 main process (3903) terminated with status 127
[  603.616917] init: thx4-web-1 respawning too fast, stopped
操作系统:Debian7、chruby(2.1.2)、upstart(1.6.1-1)和foreman(0.74.0)

只有一个进程,以简化Procfile.staging中的调试进程:

web: RAILS_ENV=staging bundle exec puma -e staging -C config/puma.rb
由工头生成的文件:

# /etc/init/thx4.conf
start on runlevel [2345]
stop on runlevel [!2345]

# /etc/init/thx4-web.conf
start on starting thx4
stop on stopping thx4

# /etc/init/thx4-web-1.conf
start on starting thx4-web
stop on stopping thx4-web
respawn
env PORT=5000
setuid deployer
chdir /home/deployer/apps/thx4/releases/20140707183433
exec RAILS_ENV=staging bundle exec puma -e staging -C config/puma.rb

当我在app文件夹中运行
$foreman start-f Procfile.staging
时,一切正常。

如果您想控制重新启动间隔,请在“重新启动”行之后添加类似的内容:

但是,我认为这不会有什么帮助。Bash状态代码127表示“未找到命令”。也许您的gems没有正确设置以适应此环境

您可以在中找到有关错误127的更多详细信息。

我是如何解决的:

我在项目根目录中创建了一个.env文件

# .env
PATH=/home/user/.gem/ruby/2.1.2/bin:/home/user/.rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/bin:/home/user/.rubies/ruby-2.1.2/bin:
RAILS_ENV=staging

# Procfile
web: bundle exec puma -e staging -C config/puma.rb
导出的文件:

# /etc/init/app-web-1.conf
start on starting app-web
stop on stopping app-web
respawn

env PORT=5000
env PATH='/home/user/.gem/ruby/2.1.2/bin:/home/user/.rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/bin:/home/user/.rubies/ruby-2.1.2/bin'
env RAILS_ENV='staging'

setuid user

chdir /home/user/apps/app/releases/20140709064220

exec bundle exec puma -e staging -C config/puma.rb
重要 我必须以root身份安装gem bundler(我不知道),就像我在这里对foreman所做的那样:
$sudo chruby exec ruby-2.1.2--gem install bundler

Upstart将您的服务执行记录在一个日志文件中,该文件名与/var/log/Upstart/your-service-name.log相同。这应该会很有帮助。

我在配置时犯了很多错误,感谢您的回答关于代码127的解释非常有用。我的问题的答案是:reason是因为在您的路径中没有附加原始路径。如果您将其更改为
PATH='/home/user/.gem/ruby/2.1.2/bin:/home/user/.rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/bin:/home/user/.rubies/ruby-2.1.2/bin':$PATH
,那么您就不必将bundler用作root,但可能是因为我使用的是rbenv,所以我的情况有点不同?
# /etc/init/app-web-1.conf
start on starting app-web
stop on stopping app-web
respawn

env PORT=5000
env PATH='/home/user/.gem/ruby/2.1.2/bin:/home/user/.rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/bin:/home/user/.rubies/ruby-2.1.2/bin'
env RAILS_ENV='staging'

setuid user

chdir /home/user/apps/app/releases/20140709064220

exec bundle exec puma -e staging -C config/puma.rb