Deploying with our main app on Passenger and Faye on Thin is currently working. But I'm having some issues transitioning from that set-up to Faye using passenger as well.
It suggests here (https://github.com/faye/faye-websocket-ruby) that I can run Faye on Passenger Standalone and start said server with this command
passenger start -p 9292
However, this doesn't even work locally. First it returns this error stating it cannot find faye.js at
http://localhost:9292/faye?message=%5B%7B%22channel%22%3A%22%2Fmeta%2Fhandshake%22%2C%22version%22%3A%221.0%22%2C%22supportedConnectionTypes%22%3A%5B%22callback-polling%22%5D%2C%22id%22%3A%221%22%7D%5D&jsonp=__jsonp1__
The error is this
Failed to load resource: the server responded with a status of 404 (Not Found)
When you change the browser to the indicated location it says
no route matches [GET] "/faye"
Looking at the passenger logs it seems to first run into this error
Started GET "/faye" for 127.0.0.1 at 2014-05-09 10:04:23 -0700
ActionController::RoutingError (No route matches [GET] "/faye"):
and then run into this one
Started OPTIONS "/faye" for 127.0.0.1 at 2014-05-09 10:04:58 -0700
ActionController::RoutingError (No route matches [OPTIONS] "/faye"):
While running using Thin I used the following command to start the server
bundle exec rackup faye.ru -s thin --daemonize -E production
There are a few differences between the passenger start I'm trying and the thin, but the largest one is that faye.ru never gets run. My faye.ru is basic
require 'faye'
faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45)
Faye::WebSocket.load_adapter('thin')
run faye_server
To switch that over to Passenger I know I need to remove the third line...but then what? When I just added this straight into my config.ru file the faye server ended up taking over the entire app, which definitely was not my aim. I thought perhaps putting it in an initializer would work, but I run into the following error:
undefined method `run' for main:Object (NoMethodError)
Which I assume is because this isn't a .ru file but a .rb file.
Regardless, I find myself rather confused, and I'd definitely appreciate any tips/directions to go.
Edit:
This site (http://rubydoc.org/github/jamesotron/faye-rails/frames) states
If you want to run faye-rails on passenger, make sure you are using passenger 4.0 standalone or passenger 4.0 on nginx 1.4+ for nginx with websocket support. Passenger on apache is not supported. Because passenger uses a multi-process model, you must use the faye redis backend. Add gem 'faye-redis' to your Gemfile and configure your routes like this:
config.middleware.use FayeRails::Middleware, mount: '/faye', :timeout => 25, server: 'passenger', engine: {type: Faye::Redis, host: 'localhost'}
However I've tried adding the relevant code to my application.rb, where I have several config commands going on within
module App
class Application < Rails::Application
but simply adding below that (where all my other config.whatever are) the code suggested above leads to this error
uninitialized constant App::Application::FayeRails (NameError)
Edit:
Added the faye-rails gem because I'm an idiot (see comments). This also required adding
config.middleware.delete Rack::Lock
because (console output)
faye-rails can't work when Rack::Lock is enabled, as it will cause
a deadlock on every request.
However, now I'm running into this error
/Users/WEF6/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require': cannot load such file -- passenger (LoadError)
This must be related to some of the changes I made as outlined in this post as I outlined above how I was receiving errors after a successful passenger start-up locally. Running passenger now the server throws the following error
Could not spawn process for group location#default: An error occured while starting up the preloader.
in 'void Passenger::ApplicationPool2::SmartSpawner::handleErrorResponse(Passenger::ApplicationPool2::SmartSpawner::StartupDetails &)' (SmartSpawner.h:455)
in 'string Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails &)' (SmartSpawner.h:566)
in 'void Passenger::ApplicationPool2::SmartSpawner::startPreloader()' (SmartSpawner.h:206)
in 'virtual ProcessPtr Passenger::ApplicationPool2::SmartSpawner::spawn(const Passenger::ApplicationPool2::Options &)' (SmartSpawner.h:752)
in 'void Passenger::ApplicationPool2::Group::spawnThreadRealMain(const SpawnerPtr &, const Passenger::ApplicationPool2::Options &, unsigned int)' (Implementation.cpp:804)
[ 2014-05-09 12:15:15.1055 71107/0x10c9ce000 agents/HelperAgent/RequestHandler.h:2222 ]: [Client 21] Cannot checkout session.
Error page:
cannot load such file -- passenger (LoadError)
You must declare the faye-rails gem in your gemfile including this line:
'faye-rails', '~> 2.0.0'
Update:
I think you can solve the rack lock issue adding the line below in your application.rb
config.middleware.delete Rack::Lock
I hope this helps you.
I noticed you're using faye.ru when running Thin. Phusion Passenger only supports config.ru as the filename for the Rack startup file. Maybe the solution is as easy as renaming faye.ru to config.ru?
Related
I made new project with Rails and Vue using webpacker. Firstly I got strange error
Cannot read property 'compile' of undefined
So I hit yarn upgrade webpack-dev-server --latest which was the correct answer and helped me but then when I hit: ./bin/webpack-dev-server my webpack dev server starts and all looks fine but at http://localhost:3035/ I am getting the "Cannot GET /" message.
JS console: Failed to load resource: the server responded with a status of 404
I also tried to reinstall webpacker...
When running your Rails application locally you'll need to start both the rails server and the webpack-dev-server. I typically use foreman with a simple Procfile, although you can also start both of these by hand.
# Procfile
server: bin/rails server
assets: bin/webpack-dev-server
Then you can run the Procfile and startup both servers with: foreman start
The webpack-dev-server port (3035) is not the port you'll be connecting to for seeing your application. Start up both servers and go to localhost:3000 and you'll see your rails application root path page (or default rails page if you dont have routes yet).
One thing to note, if you're using Foreman to start your servers it will default your rails port to 5000 instead of 3000. You can configure this either in the Procfile or when you call foreman if you want different behavior.
I'm trying to start rails server (puma) using command rails s
I get this error:
rails s I, [2017-11-16T10:47:05.872867 #16905] INFO -- sentry: **
[Raven] Raven 2.5.1 configured not to capture errors: Not configured
to send/capture in environment 'development'
=> Booting Puma
=> Rails 5.1.3 application starting in development on http://localhost:3000
=> Run rails server -h for more startup options Exiting /home/mariusz/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:in require': libssl.so.1.0.2: cannot open shared object file: No such
file or directory -
/home/mariusz/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/puma-3.10.0/lib/puma/puma_http11.so
(LoadError) from
/home/mariusz/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.3/lib/active_support/dependencies.rb:292:inblock in require'
My project info:
puma (3.10.0), rails (5.1.3), ruby 2.4.0
The problem was with invalid environment. I needed to restore all my gems to pristine state. Running gem pristine --all helped. (it takes about 10 min to finish it)
I solved the problem this way.
Go to the tmp/pids folder then in the server.pids file erases the content of this file. The content is the pid of the server rails execution process.
Just FYI, this is the first time I'm deploying something on a production server. I went through this guide as my server is also hosted on DO.
The environment is pretty much the same - I'm using Ubuntu 14.04, Ruby 2.3.3 (rbenv) and rails 5.
I followed everything step by step and I have gotten no error, however, now I'm getting a 502 bad gateway when accessing my public IP.
I have noticed that for some reason after starting puma manager (sudo start puma-manager), the directory "shared/sockets/puma.sock" is not getting created.
When I start puma manually by using -> RACK_ENV=production bundle exec puma -C config/puma.rb from my app directory, I get the following error:
bundler: failed to load command: puma (/root/.rbenv/versions/2.3.3/bin/puma)
Errno::ENOENT: No such file or directory - connect(2) for /root/belooga/shared/sockets/puma.sock
Any idea of what I might be doing wrong? Should you need to see any file, please let me know and I'll provide anything that might be needed.
Cheers!
EDIT:
I have double-checked all the paths in:
myapp/config/puma.rb
/etc/puma.conf
/etc/nginx/sites-available/default
... the directory "shared/sockets/puma.sock" is not getting created.
Here is your problem, create the directory before you start the puma server.
MyApp is set up using:
ubuntu
rbenv
ruby 2.0
rails 4.0
unicorn
capistrano
With Capistrano's deploy strategy, the path to my app is /srv/www/my_app/current/
I'd expect to have RAILS_ROOT be the same.
When I am logged onto my remote server, am in that path, and run:
unicorn_rails -c /srv/www/my_app/current/config/unicorn.rb -D
I get the following error in the unicorn.stderror.log:
/home/ubuntu/.rbenv/versions/2.0.0-p247/bin/unicorn_rails must be run inside RAILS_ROOT: #<LoadError: cannot load such file -- /srv/www/my_app/config/boot>
I've tried all sorts of things to set RAILS_ROOT, with no luck.
I thought RAILS_ROOT was actually Rails.root now
I saw somebody post that it should be defined in boot.rb but that would mean that the load error above is finding boot.rb and then complaining that it can't find it.
From Deefour's comment, I switched from using unicorn_rails to unicorn executable.
I have a locally developed Rails application. It is very simple, with no database but only a controller that accesses Facebook data and renders them in view. By the way, gem RestGraph is used.
Before I push this application to heroku, I used foreman start to test it. Since I was using WEBrick before I need to install 'thin' gem and create a Procfile which reads:
web: bundle exec thin start -R config.ru -e $RACK_ENV -p $PORT
an '.env' file seems also required, which reads:
RACK_ENV=development
PORT=3000
The 'config.ru' file is generate by rails, which reads:
require ::File.expand_path('../config/environment', __FILE__)
run Myapp::Application
Now I entered 'foreman start', but all I get is one line:
15:33:18 web.1 | started with pid 27143
The server will not boot. And if I force terminate it, the error is:
/usr/local/foreman/lib/foreman/engine.rb:141: [BUG] rb_sys_fail() - errno == 0
Which is not very helpful.
It may be that instead of being "stuck," your log is just being buffered: foreman only shows line with “started wit pid #” and nothing else
I solved that issue by adding
$stdout.sync = true
to config.ru
Then you might get more helpful feedback from Foreman.
This seems a little over complex. From looking at a couple of apps I have I have the following in my procfile:
bundle exec rails server thin -p $PORT
I also don't have a .env file in these instances.
One thing worth noting is that Foreman will ignore the port you pass in most of the time, it likes to sit in a port range higher than 5000