我有一個unicorn.rb文件,我想根據環境變量設置worker_process。我試過沒有成功以下方法:根據環境變化Unicorn worker_process
environment = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'production'
# Save on RAM while in development
if environment == 'development'
worker_processes 1
else
worker_processes 4
end
當我使用foreman start
我得到以下錯誤:
21:07:49 web.1 | /home/hg/.rvm/gems/[email protected]/gems/unicorn-4.3.1/lib/unicorn/configurator.rb:74:in `instance_eval': ./unicorn.rb:4: syntax error, unexpected ':', expecting keyword_then or ';' or '\n' (SyntaxError)
21:07:49 web.1 | ./unicorn.rb:6: syntax error, unexpected keyword_else, expecting $end
21:07:49 web.1 | from /home/hg/.rvm/gems/[email protected]/gems/unicorn-4.3.1/lib/unicorn/configurator.rb:74:in `reload'
21:07:49 web.1 | from /home/hg/.rvm/gems/[email protected]/gems/unicorn-4.3.1/lib/unicorn/configurator.rb:67:in `initialize'
21:07:49 web.1 | from /home/hg/.rvm/gems/[email protected]/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:104:in `new'
21:07:49 web.1 | from /home/hg/.rvm/gems/[email protected]/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:104:in `initialize'
21:07:49 web.1 | from /home/hg/.rvm/gems/[email protected]/gems/unicorn-4.3.1/bin/unicorn_rails:209:in `new'
21:07:49 web.1 | from /home/hg/.rvm/gems/[email protected]/gems/unicorn-4.3.1/bin/unicorn_rails:209:in `<top (required)>'
21:07:49 web.1 | from /home/hg/.rvm/gems/[email protected]/bin/unicorn_rails:19:in `load'
21:07:49 web.1 | from /home/hg/.rvm/gems/[email protected]/bin/unicorn_rails:19:in `<main>'
21:07:49 web.1 | from /home/hg/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `eval'
21:07:49 web.1 | from /home/hg/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `<main>'
21:07:49 web.1 | exited with code 1
21:07:49 system | sending SIGTERM to all processes
SIGTERM received
我能請得到的我怎麼能解決這個指針?謝謝。
這是整個unicorn.rb文件嗎?你可以將它完全粘貼,還是要求它或確認它確實滿了?我看到它在抱怨:在我無法辨認的第4行。第一個建議是避免將環境作爲一個變量,因爲它可能在獨角獸內部使用? –
這是我完整的[gist文件](https://gist.github.com/4633113)。奇怪的是,現在我再試一次,它正在工作。 – Hengjie
我懷疑你可能遺漏了一個:在那裏是錯誤的。 :)使用vi/vim? –