开发者

Sinatra on Passenger always fails on first attempt

开发者 https://www.devze.com 2022-12-17 14:32 出处:网络
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 applica开发者_开

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 applica开发者_开发知识库tion 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?


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!


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号