如何使用Unicorn和配置文件启动Rails服务器的生产模式?

18
我在Gemfile中添加了 Gem 'unicorn',然后调用 rails server unicorn -e production,但是出现了加载错误。 然后我添加了Gem 'unicorn_rails',再次调用 rails server unicorn -e production,但是找不到套接字文件。所以我在考虑它是否没有使用 config/unicorn.rb 文件作为配置?于是我调用了 unicorn_rails -c config/unicorn.rb -E production -D,但是我又遇到了另一个 error text file busy
所以现在我被卡住了,你可以帮助我吗?:)

1
根据这个https://dev59.com/T2ct5IYBdhLWcg3wIqDW#12326124,只需使用'unicorn' gem而不是'unicorn_rails' gem。 - lulalala
3个回答

36

它应该是类似于这样的东西:

bundle exec unicorn -E production -c config/unicorn.rb

你只需要使用 unicorn gem。


我认为你已经回答了我的问题(关于使用独角兽和配置),谢谢。顺便说一下,这个命令引发了另一个错误: /usr/local/rvm/gems/ruby-2.0.0-p0-turbo/gems/unicorn-4.2.1/lib/unicorn/http_server.rb:202:in 'rename': Text file busy - (/vagrant/ruby-china/tmp/pids/0.2628933382622929.13474, /vagrant/ruby-china/tmp/pids/unicorn.pid) (Errno::ETXTBSY),你能帮我吗? - Sefier Tang

5

bundle exec unicorn -p $PORT -c ./config/unicorn.rb

对于我来说可行。

我把它放在 Procfile 文件中,然后使用 Foreman 来启动,只需输入:

foreman start


2
您在哪里定义$PORT变量的值? - lucke84
同样的问题...我可以成功运行bundle exec unicorn -p 5000 -c ./config/unicorn.rb,但无法运行bundle exec unicorn -p $PORT -c ./config/unicorn.rb。 - Ben Wheeler
添加-D选项以使其变成守护进程 - alexey_the_cat

0
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

service unicorn_projectName start

对我有效


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接