Force start Rails application through foreman only - ruby-on-rails

I am using foreman in my Rails application and all works fine when I run foreman start but sometime I forget it and run only Rails application as rails s. Then I spend some time trying to investigate problems related to not working services (like sidekiq).
So, can somebody recommend a way how to force starting my application through foreman only? In other cases I want to see error message.

You could add an environment variable to .env, which is read when Foreman starts, and then check for its presence in a Rails initializer.

Related

Prevent foreman to crash when typo in code

I am using foreman gem on my Rails project to handle the different processes to be launched at startup (web, mailer, delayed job, ...).
It's working as expected but if I save a file with a typo or try to access a property on a nil object, foreman crash for all processes. I have to manually kill each ruby and node (for maildev) processes in order to run foreman start again.
Is there a way to prevent foreman to crash as the plumber plugin for gulp tasks ?
Thanks !
My project:
Rails 4.2
Ruby 2.2.0
Foreman
Server Unicorn
Mac OSX

running rails console in Capistrano deployed app

I've deployed a Rails app to AWS using Capistrano, and now I'm trying to start Rails console, but can't. If I go into home/user/app-name/current/ and try running rails c I just get instructions on how to use the rails command.
Alternatively, I need to run a command, specifically a Searchkick command ClassName.reindex is there a way I'm missing to do this without opening the console?
rails c is probably failing due to the fact that you are missing bin/rails in your deployed app. See this answer for a fix: Rails 4 doesn't detect application after capistrano deployment
Once you get bin/rails working, you can run a command without using the console like this:
bundle exec rails runner ClassName.reindex
The runner Rails command loads your app and evaluates whatever Ruby code you supply.
Depending on how you've done your deployment, you may need to explicitly specify the environment, like this:
bundle exec rails runner -e production ClassName.reindex
Take a look at these and let m,e know if you find them to be helpful.
https://github.com/ydkn/capistrano-rails-console
https://gist.github.com/benedikt/1115513

Using JRuby and MRI for a common app

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.

Speeding up rails development deployment

I got a rails app that requires redis, mongod, and postgres before starting with rails s. I do not like open several tabs on my terminal and open these services one by one. Is there a way to run everything with one command/script? Is there a specific gem that might help with this? Thanks.
one way is mentioned by #Tres with using the foreman gem. If you are using rvm you can use a .rvmrc file in your project. There you can simply define some shell commands like
mongod --port 23017
postgresql start
and the like ...

Running nginx in rails automatically

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.

Resources