I have a nodeJS app that does some calculations. I'm curious if there's a way(and makes sense) creating a rails gem for my app that'd run that nodeJS app and communicate with rails (I'm using heroku)
I ended up running nodejs app as a separate app with a shared REDIS. I used REDIS subscribe (pub/sub) to communicate between rails app and nodejs up, and a constantly running rake task on rails side that'd create sidekiq jobs for messages from nodejs app.
However, it's as easy just to run nodejs app on a worker specifying it in the Procfile, like:
nodejs: node nodeapp/index.js
Related
I've developed my Rails project locally and want to deploy it on my Ubuntu VPS. Now I've installed the gems on the VPS and copied my Rails App code to it. I can execute rails s --binding=0.0.0.0 in a putty session to the VPS and the website can be access from the Internet. The problem is when I close putty, the website is down. How to start my Rails App in a way that it still alive even if I closed putty?
Using rails s is not the way to go. It will use Webrick(or a different one if you choose) to handle the requests and it can be quite slow.
You should setup a production stack for serving your website.
Here is one of the best tutorials I've seen about how to deploy a Rails app to a production server(VPS).
In short you gonna need install RVM or Rbenv, Ruby, some libs, Database, Nginx and Passenger. You have alternatives too. But this is the basic.
I recommend using Capistrano for deploy. You can choose another deployment tool also, or none.
rails s it is best for development only.
Has any one used Capistrano 3.0.0 ?
I'm new to rails and web development in general, and I've never used Capistrano before, and I need to deploy my app on Heroku with Capistrano in order to user sidekiq and redis-server.
Should I use an older version of Capistrano, where I could find more resource to help get started, or is this considered a bad thing ?
Any suggestions or tips would be very much appreciated.
Capistrano and Heroku are not compatible technology.
Heroku provides a git source control remote server. When you want to deploy code onto your Heroku app, you use git to push a copy of the code. This triggers a Heroku deployment through their process.
Capistrano is an SSH based system deployment framework. It allows you to connect via SSH to each server in your environment and issue commands with a large library of built-in functionality. Heroku does not allow SSH access to configure systems.
Do you have deploys/configuration working on Heroku at all? If not, you should start there with the basic Heroku Rails setup documents.
If you do have your web app running, but need Redis and Sidekiq, you will need to:
Provision a Redis database provider, like OpenRedis via a Heroku Addon: http://addons.heroku.com/
Setup Sidekiq in your Rails application (See Sidekiq docs: https://github.com/mperham/sidekiq)
Add a Sidekiq worker process in your Heroku Procfile within your app
Your app will then have a number of web processes from the Procfile running your Rails app front-end and a number of back-end asynchronous workers running Sidekiq.
I have a Rails app hosted on Heroku and I want to add Server Sent Events functionalities, but I can't find any documentation or blog post specific for Heroku.
As not all servers (e.g. WEBrick) support ActionController::Live I was wondering what is the default server on Heroku and whether is possible to configure the environment (i.e. change server) to support SSEs.
Any further advice about the server to use and how to configure would be greatly appreciated.
I think my answer is not so widely helpfull, but you can try.
For the first thing:
create Procfile in rails root within the following content:
web: bundle exec rails server puma -p $PORT -e $RACK_ENV
then add to Gemfile:
gem 'puma'
In above you can switch to thin, but consider link below (and many more details)
http://tenderlovemaking.com/2012/07/30/is-it-live.html
Heroku wouldn't necessarily be the issue here - it's an environment which allows your app to run (on Amazon EC2 I think)
Multi-Threaded Servers
The thing you've got to look for is the server software you use to run your app. Heroku basically takes your server gem & allows it to run with their processors, and other computing power; so it's really whether their platform can play ball with the right server
You're really looking for multi-threaded servers, which you can find here Is puma the ONLY multi-threaded rails 4 http server?
Puma
Rainbows! supports multiple concurrency models, including multithreading
Zbatery - Rack HTTP server without a fork stuck in it
Phusion Passenger 4 has supported multithreading since its beta stages
Thin does have a threaded mode which can be enabled by passing
--threaded or by setting threaded: true in the appropriate configuration file (e.g. bundle exec thin start --threaded)
Net::HTTP::Server, despite the lack of advertising, supports
multithreading; very minimalist
I need to use both JRuby and MRI for my rails app.
Here's the scenario -
My app uses a background server which handles a lot of threads. I'm having performance
issue with running it on MRI. The background server is started with a rake task and needs
to use the Rails environment.
I'm using Passenger for the Web Server. Since JRuby support for Passenger is quite recent,
I would like to go with using MRI.
Here's something I want -
This uses Ruby 1.9 to start the server :
sudo passenger start -p 80 -e production --user=deploy
and within the same app, this runs the background server -
jruby -S rake background_server:start_daemon RAILS_ENV=production
The problem is, the second command jruby -S rake asks for rebundling the app.
Is there any way I can get this in place?
Not in the same app. you'll need separate applications that run under different rubies if you want this to happen. in SOA architecture, you'd send a message to your background server for it to process a job.
So, in heroku you'd create one application for your web running in MRI; then you'd create an application in JRuby for your background processes. They'd communicate via a shared Redis or shared database.
I would recommend using Trinidad or Puma and keeping it all in JRuby though (as opposed to keep running passenger); it'll be a much simpler architecture.
I am using rails 2.3.9, rubygems 1.8.24, ruby 1.9.3 and Windows 7 ultimate 64-bit
I just installed nginx as my web server through passenger. Now I want to run nginx as my default server such that when i run ruby script/server, it runs instead of the default WeBrick. Is there any way to do this? Thanks a million.
Nginx doesn't work the way you described. Once it is started, you won't need to run script/server, the rails app will be run at the same time when the Nginx/Apache started.
So, just deploy your rails app following the 'Passenger' manual( in development mode), and you will get your app always running.
so, as conclusion, we can tell that, when deploying a Rails app, Nginx and Apache is in the same group( work together with Passenger), and Mongrel/Webrick/Thin is another group(script/server approach).
You may want to take a look at Foreman.