Sinatra app on Passenger can't find Rack (using RVM) - sinatra

I've been fighting with a staging server for this Sinatra app for two days. I'm getting pretty frustrated. The latest pothole is a Ruby error handed up by Passenger:
no such file to load -- rack
The nginx.conf file shows which Ruby we're using, and where Passenger is located:
passenger_root /usr/local/rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.5;
passenger_ruby /usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby;
OK, so that's Ruby 1.9.2 for us.
The vhost configuration includes:
root /var/www/staging-proweb/current/rack/public;
passenger_enabled on;
rack_env staging;
and the rackup file has:
require 'rubygems'
require 'sinatra'
require 'myapp1.rb'
run Sinatra::Application
which then sends us to the myapp1.rb file, which includes
require 'rubygems'
require 'rack'
require 'sinatra'
...and I assume the sinatra require is what's calling for rack.
The gem's there:
~$ which ruby
/usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby
~$ gem list rack
*** LOCAL GEMS ***
rack (1.2.2)
rack-flash (0.1.1)
The error seems to be in a file in the RVM directory, judging from the first three lines of the stack trace:
0 /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb 36 in `require'
1 /usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb 36 in `require'
2 /usr/local/rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.5/lib/phusion_passenger/rack/application_spawner.rb 219 in `load_rack_app'
What should I try next? I'm pretty stumped at this point.

It looks like the issue was with the passenger_ruby configuration value. RVM provides a wrapper to set up the appropriate environment for that Ruby (including the gems), so the passenger_ruby line should have read
passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.2-p180/ruby;
With that in place, we seem to be up and running.

Related

Perl modules not installing. sh: 1: gzip: Exec format error

I am getting issues when trying to install Perl modules on Ubuntu running on Windows 10.
I am not sure the best way to post the output, I am guessing maybe as "code"
$ cpan HTTP::Tiny
Loading internal logger. Log::Log4perl recommended for better logging
Reading '/home/user/.cpan/Metadata'
Database was generated on Sun, 06 Nov 2022 23:29:01 GMT
Running install for module 'HTTP::Tiny'
Fetching with HTTP::Tiny:
http://www.cpan.org/authors/id/D/DA/DAGOLDEN/HTTP-Tiny-0.082.tar.gz
Fetching with HTTP::Tiny:
http://www.cpan.org/authors/id/D/DA/DAGOLDEN/CHECKSUMS
Checksum for /home/user/.cpan/sources/authors/id/D/DA/DAGOLDEN/HTTP-Tiny-0.082.tar.gz ok
sh: 1: /usr/bin/gzip: Exec format error
/usr/bin/tar: This does not look like a tar archive
/usr/bin/tar: Exiting with failure status due to previous errors
Uncompressed /home/user/.cpan/sources/authors/id/D/DA/DAGOLDEN/HTTP-Tiny-0.082.tar.gz successfully
Using Tar:/usr/bin/tar xf "HTTP-Tiny-0.082.tar":
Untarred HTTP-Tiny-0.082.tar successfully
'YAML' not installed, will not store persistent state
Package contains both files[HTTP-Tiny-0.082.tar] and directories[HTTP-Tiny-0.082]; not recognized as a perl package, giving up
Configuring D/DA/DAGOLDEN/HTTP-Tiny-0.082.tar.gz with Makefile.PL
Running make for D/DA/DAGOLDEN/HTTP-Tiny-0.082.tar.gz
make: *** No targets specified and no makefile found. Stop.
DAGOLDEN/HTTP-Tiny-0.082.tar.gz
/usr/bin/make -- NOT OK
I am really suck on how to fix this, I have been scratching my head for a few days now and any assistance would be really appreciated.
Based on the log it seems to be an issue specifically with Ubuntu 22.04 on WSL1:
sh: 1: gzip: Exec format error
see: gzip from Ubuntu Jammy doesn't execute #8219
You could install an earlier version of gzip via. apt that works well – however the best route would be to update to WSL 2, as it has many benefits and it won't have this issue.
See the comparison page including some rare cases where you might want to stay on WSL 1.

Setting up SimpleSAMLphp as a SP for CodeIgniter

I have to continue on an already existing CodeIgniter 3 application (not written by me) which contains multiple applications for different customers, the project structure looks a little like this:
root/
applications/
customer1/
config/, controllers/, models/, views/, ...
third_party/
SimpleSAMLphp/
config/, metadata/, www/, ...
lib/
_autoload.php
customer2/
...
assets/, bundle/, ...
customers/
customer1/
assets/, index.php, ...
customer2/
...
system/
vendor/
composer/
autoload.php
Now for one of the applications I have to replace the ion_auth system with an SSO (setup as a Service Provider from their IdP metadata). I googled a lot and tought SimpleSAMLphp would be my best option.
But I am really struggling just even putting the SimpleSAMLphp SP API into my application and the documentation isn't great.
-I "include_once" the third_party/SimpleSAMLphp/lib/_autoload.php file in the customers/customer1/index.php file (before require_once BASEPATH...)
-I modified third_party/SimpleSAMLphp/lib/_autoload.php so it finds the vendor/autoload.php file
I expect to be able to use the methods of the SimpleSAMLphp library but instead I get the following errors:
-If I follow the code in this guide:
Fatal error: Call to undefined function SimpleSAML\Auth\Simple()
-If use include APPPATH . 'third_party\SimpleSAMLphp\www\index.php in my controller just above the code from above tutorial:
Fatal error: Class 'SimpleSAML\Error\Assertion' not found in
What am I doing wrong in my setup?

Could not find rake-12.3.0 in any of the sources (Bundler::GemNotFound) - Bitnami Redmine Stack 3.3.1-0 on Ubuntu 16.04.2 LTS

I am using the Bitnami Redmine Stack 3.3.1-0 on Ubuntu 16.04.2 LTS.
I recently installed a plugin (Issue Templates - http://www.redmine.org/plugins/redmine_issue_templates).
In the process, I updated the gems using bundle install and bundle update.
After performing this update, the Redmine website no longer works. I get the error:
"We're sorry, but something went wrong. We've been notified about this issue and we'll take a look at it shortly."
Upon analyzing the apache error log, I find the error:
"Could not find rake-12.3.0 in any of the sources (Bundler::GemNotFound)"
However, I have checked /opt/bitnami/apps/redmine/htdocs/vendor/ and /opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems and rake-12.3.0 is included in both locations. I am not sure why this issue is occuring.
I uninstalled the plugin and removed the files, but I still have the issue. I tried bundle install, bundle update, gem install rake -v '12.3.0', bundle exec rake rails:update:bin in the /opt/bitnami/apps/redmine/htdocs/ folder, and I also tried ./gem update in the /opt/bitnami/ruby/bin folder, but I still have the issue.
Please advise me what to do.
[ 2018-03-15 15:35:23.8349 28957/7f4ce96ec700 age/Hel/Req/CheckoutSession.cpp:252 ]: [Client 4-1] Cannot checkout session because a spawning error occurred. The identifier of the error is 35671c4a. Please see earlier logs for details about the error.
App 4445 stdout:
App 4445 stderr: /opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/passenger-5.0.6/lib/phusion_passenger/config/system_metrics_command.rb:34: warning: Insecure world writable dir /opt/bitnami/ruby/bin in PATH, mode 040757
App 4445 stdout:
[ 2018-03-15 15:35:29.9175 28957/7f4ce86a9700 App/Implementation.cpp:287 ]: Could not spawn process for application /opt/bitnami/apps/redmine/htdocs/: An error occured while starting up the preloader.
Error ID: 16a39427
Error details saved to: /tmp/passenger-error.3ZEVOb
Message from application: <p>It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:</p>
<pre class="commands">bundle install</pre>
<p>If that didn't work, then the problem is probably caused by your application being run under a different environment than it's supposed to. Please check the following:</p>
<ol>
<li>Is this app supposed to be run as the <code>daemon</code> user?</li>
<li>Is this app being run on the correct Ruby interpreter? Below you will
see which Ruby interpreter Phusion Passenger attempted to use.</li>
</ol>
<p>-------- The exception is as follows: -------</p>
Could not find rake-12.3.0 in any of the sources (Bundler::GemNotFound)
<pre> /opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/spec_set.rb:88:in `block in materialize'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/spec_set.rb:82:in `map!'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/spec_set.rb:82:in `materialize'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/definition.rb:170:in `specs'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/definition.rb:237:in `specs_for'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/definition.rb:226:in `requested_specs'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:108:in `block in definition_method'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:20:in `setup'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler.rb:107:in `setup'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/bundler-1.16.1/lib/bundler/setup.rb:20:in `<top (required)>'
/opt/bitnami/ruby/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `require'
/opt/bitnami/ruby/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
/opt/bitnami/ruby/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:in `require'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/passenger-5.0.6/lib/phusion_passenger/loader_shared_helpers.rb:278:in `block in run_load_path_setup_code'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/passenger-5.0.6/lib/phusion_passenger/loader_shared_helpers.rb:381:in `running_bundler'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/passenger-5.0.6/lib/phusion_passenger/loader_shared_helpers.rb:276:in `run_load_path_setup_code'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/passenger-5.0.6/helper-scripts/rack-preloader.rb:99:in `preload_app'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/passenger-5.0.6/helper-scripts/rack-preloader.rb:157:in `<module:App>'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/passenger-5.0.6/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
/opt/bitnami/ruby/lib/ruby/gems/2.1.0/gems/passenger-5.0.6/helper-scripts/rack-preloader.rb:28:in `<main>'</pre>
[ 2018-03-15 15:35:29.9342 28957/7f4ceaeef700 age/Hel/Req/CheckoutSession.cpp:252 ]: [Client 1-2] Cannot checkout session because a spawning error occurred. The identifier of the error is 16a39427. Please see earlier logs for details about the error.
Did you load the Bitnami environment before running the "bundle" commands? There's a script at /opt/bitnami/ called "use_redmine". Please run it before running the commands.
For instance:
/opt/bitnami/use_redmine
cd /opt/bitnami/apps/redmine/htdocs/
bundle ...
Note: if you installed the Redmine Stack as superuser "root" on your Ubuntu, you need to load the environment using sudo /opt/bitnami/use_redmine

Couldn't load the Unicode tables for UTF8Handler in Rails Admin (1.2.0)

I want to upgrade rails 3 to rails 5. There I am using mongodb as database. I am using rails admin 1.2.0. I am using jruby-9.1.7.0. I am rails api only app. My application gems are given below.
gem 'rails', '~> 5.1.4'
gem 'awesome_print', '~> 1.8.0'
gem 'devise', github: 'plataformatec/devise', :branch => 'master', :ref => "463351922fdafb96c50ba2496c7d0adaa3223283"
gem "doorkeeper-mongodb", github: "doorkeeper-gem/doorkeeper-mongodb"
gem 'cancan', github: 'DevAVIJIT7/cancan', :branch => 'master', :ref => "aa3729bd79d92a993c5186f983eccd2fd496c2d3"
gem 'puma','~> 3.11.0'
gem 'mongoid', '6.2.1'
gem 'mongoid-tree', '~> 2.1.0'
gem 'rails_admin', '~> 1.2'
In my routes rails admin mount path and initializer file look like
mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
RailsAdmin.config do |config|
RAILS_ADMIN_BASE_PATH = 'godview'
config.main_app_name = Proc.new do |controller|
[ "Admin", "#{controller.params[:action].try(:titleize)}" ]
end
config.authenticate_with do
authenticate_or_request_with_http_basic('Login required') do |username, password|
user = User.where(username: username).first
if user && user.valid_password?(password) && user.role_names.include?("Super Admin")
user
else
nil
end
end
end
end
when I run http://localhost:3000/admin on browser I am getting error.
In console I am getting
Started GET "/godview" for 0:0:0:0:0:0:0:1 at 2018-01-15 14:54:12
+0530
Processing by RailsAdmin::MainController#dashboard as HTML
Completed 401 Unauthorized in 263ms
IOError (Couldn't load the Unicode tables for UTF8Handler (undefined method
`call' for nil:NilClass
Did you mean? caller), ActiveSupport::Multibyte is unusable):
I went through the link Rails: Couldn't load the Unicode tables for UTF8Handler But didn't get any response.
*note : I am using /admin as /godview in my app.
Thanks
We are using Docker on CentOS for our rails projects, and we got this error recently, we fixed it by explicitly specifying the C.UTF8 encoding in the docker file as below:
ENV LANG C.UTF-8
Encoding
By default, Ruby inherits the locale of the environment in which it is run. For most users running Ruby on their desktop systems, that means it's likely using some variation of *.UTF-8 (en_US.UTF-8, etc). In Docker, however, the default locale is C, which can have unexpected results. If your application needs to interact with UTF-8, it is recommended that you explicitly adjust the locale of your image/container via -e LANG=C.UTF-8 or ENV LANG C.UTF-8
References:
https://hub.docker.com/_/ruby/
https://oncletom.io/2015/docker-encoding/

Can't run Capistrano - dependency error

I've installed Capistrano on my Ubuntu with the following commands
sudo gem install capistrano
sudo gem install railsless-deploy # I want to deploy a PHP website
sudo gem install capistrano-ext
When I run "capify ." in my deployment folder, have got an error:
Same error with other Capistrano command like a simple "cap -h" ...
/usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find capistrano (>= 0) amongst [POpen4-0.1.4, Platform-0.4.0, addressable-2.3.4, addressable-2.3.2, bundler-1.3.5, bundler-1.2.3, bundler-1.0.21, chunky_png-1.2.8, chunky_png-1.2.7, coderay-1.0.9, coderay-1.0.8, commonjs-0.2.6, compass-0.12.2, compass-normalize-1.4.3, compass-normalize-1.4.2, compass-recipes-0.3.0, em-websocket-0.5.0, em-websocket-0.4.0, eventmachine-1.0.3, eventmachine-1.0.0, ffi-1.7.0, ffi-1.3.1, forge-0.5.0, formatador-0.2.4, fssm-0.2.10, fssm-0.2.9, guard-1.8.0, guard-1.7.0, guard-1.6.1, guard-1.3.3, guard-livereload-1.3.0, guard-livereload-1.2.1, guard-livereload-1.1.3, guard-livereload-1.0.1, hike-1.2.2, hike-1.2.1, http_parser.rb-0.5.3, json-1.7.7, json-1.7.6, json-1.6.5, less-2.3.2, less-2.2.2, less-2.0.8, libv8-3.16.14.1, libv8-3.11.8.13-x86-linux, libv8-3.3.10.4-x86-linux, listen-1.0.2, listen-0.7.3, listen-0.7.2, lumberjack-1.0.3, lumberjack-1.0.2, method_source-0.8.1, multi_json-1.7.2, multi_json-1.5.0, open4-1.3.0, pry-0.9.12.1, pry-0.9.12, pry-0.9.11.4, rack-1.5.2, rack-1.5.0, rack-1.3.5, rake-10.0.4, rake-10.0.3, rake-0.9.2.2, rb-fsevent-0.9.3, rb-inotify-0.9.0, rb-kqueue-0.2.0, ref-1.0.4, ref-1.0.2, rubygems-update-2.0.3, rubygems-update-1.8.25, rubyzip-0.9.9, sass-3.2.8, sass-3.2.7, sass-3.2.5, sassy-buttons-0.1.4, slick-buttons-0.0.6, slop-3.4.4, slop-3.4.3, sprockets-2.9.3, sprockets-2.9.2, sprockets-2.8.2, sprockets-2.0.3, sprockets-helpers-1.0.1, sprockets-helpers-1.0.0, sprockets-helpers-0.8.0, sprockets-sass-1.0.0, sprockets-sass-0.9.1, sprockets-sass-0.3.0, stitch-0.1.6, therubyracer-0.11.4, therubyracer-0.11.3, therubyracer-0.9.9, thor-0.18.1, thor-0.17.0, thor-0.15.4, tilt-1.3.7, tilt-1.3.3, yui-compressor-0.9.6] (Gem::LoadError)
from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
from /usr/local/bin/cap:22:in `<main>'
I'm a noob with Capistrano and Ruby
Any idea to resolve this problem ?
Thx
Probably what's going on is that you installed Capistrano as the root user. However, running capify from a non-root user account is trying to find Capistrano installed for that specific user rather than a system-wide install.
Can you run simply
gem install capistrano railsless-deploy capistrano-ext
As the user, without Sudo?
To answer your comment: It's generally not best practice to be installing and running cap deploy scripts as the root user. For your purposes maybe it will be OK, since you are doing a very limited task with Ruby/Cap; in the future, I would recommend looking into something like RVM.
RVM (Ruby Version Manager) is a tool you will be able to install system-wide, that then will manage your ruby version and gems per user.