Sinatra on Passenger always fails on first attempt

感情迁移 提交于 2019-12-10 23:08:47

问题


I have a small Sinatra app I'm running on a shared hosting account using Passenger. However, the first time the app is accessed after a while, I get a Passenger error page saying the application could not be started. Usually because Sinatra could not be found.

I am assuming this is just a normal delay from when a new instance is spawned. However, is there a way to delay trying to load Siantra until it Passenger has fully loaded?


回答1:


I seem to have solved the issue by setting the GEMS_PATH environment variable in the .htaccess file. I haven't encountered the error again. YET!




回答2:


I took this up with Dreamhost support recently (not a great experience) and eventually they recommended freezing the gems into the application. This is at best a partial solution, because it seems to work for some gems and not for others.

Instead of

require 'sinatra'

I have:

require 'vendor/gems/sinatra-0.9.4/lib/sinatra'

Freezing gems is covered elsewhere, but briefly: to prepare for this, one needs to do

mkdir vendor/gems
cd vendor/gems
gem unpack sinatra

As a result of this change, I never get the startup failure screen quoting sinatra as the file it can't load. However, I still get it for some other gems which require themselves or parts of other gems. Not too clear about the details, but I'm working on the idea of hacking the installed gems to make every "require" use a path directly out of my "vendor" library.




回答3:


I think you may need to add Gem.clear_paths! in there




回答4:


I had a similar problem a long time ago. Updating to a newer Sinatra gem helped me - what version are you running?



来源:https://stackoverflow.com/questions/2116837/sinatra-on-passenger-always-fails-on-first-attempt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!