How to make/monitor/deploy daemon processes in JRuby - ruby-on-rails

I'm currently porting a Rails App currently using REE to JRuby so I can offer an easy-to-install JRuby alternative.
I've bundled the app into a WAR file using Bundler which I'm currently deploying to GlassFish. However, this app has a couple of daemon processes and it would be ideal if these could be part of the WAR file, and potentially monitored by Glassfish (if possible).
I've looked at QuartzScheduler, and while meets my needs for a couple of things, I have a daemon process that must execute every 20 seconds as it's polling the database for any delayed mail to send.
If anyone can provide any insight as to how best to set up daemon processes in a JRuby/Java/Glassfish environment any help will be greatly appreciated! :)

One way to daemonize a JRuby process is to use akuma framework (on *nix) or others.
I would rather use cronjobs (schedulling) rather than daemons as they are less error-proned, daemons can leak memory, can stop on errors etc. Check jruby-quartz and quartz_scheduler
EDIT
If one uses Torquebox it offers support for services and scheduling.

Related

Rails 3 Sidekiq Passenger

I am able to get Sidekiq scheduler working locally. The last obstacle in my way is how to deploy this to a production app on passenger. Can someone point me in the right direction on how to run Sidekiq continuously on passenger.
Appreciate it.
Passenger is a Apache\nginx module for running Rails\Rack apps.
Sidekiq is a threaded background worker queue that usually is run with JRuby in production.
You do not run Sidekiq through Passenger.
Rather, just configure Passenger to run and serve you app as needed. Then you can start Sidekiq and have it poll Redis for work. It is highly recommend you use either JRuby or Rubinius so you take full advantage of Sidekiq's threaded nature.
For more details on deploying Sidekiq, refer to the wiki:
https://github.com/mperham/sidekiq/wiki/Deployment
For more details on configuring Passenger refer to it's docs (for either Apache or nginx):
https://www.phusionpassenger.com/support#documentation
Update: From the creator of Sidekiq there is a library called Girl Friday. This library adds an asynchronous job queue but runs inline with your Rails application (or other Rack app). This option can greatly simplify deployment and save money!

Any background process gems that work with JRuby deployed on Windows?

Does anyone know a working background job solution for JRuby deployed on a windows server? (via warbler and tomcat)
I'm looking for a way to schedule background jobs from my Rails 3.2 app, so that the web app can respond immediately rather than hang up while a long running job runs.
I tried the delayed_job gem, except it doesn't seem to work with JRuby and Windows. (If I'm wrong, please enlighten me) Resque depends on redis which evidently doesn't support Windows. I don't have experience with Beanstalkd or Starling, but the documentation for them doesn't mention windows.
I'ld love to dump windows, believe me, but the background job is a windows executable that did not come with source. And I need to use JRuby to be able to call some Java code too.
Solved the problem using the jruby-rack-worker gem, http://github.com/kares/jruby-rack-worker, which let's you use delayed_job to schedule jobs, just provides a different way to kickoff worker processes that is more JRuby/Warbler/Tomcat friendly.
We use Rufus Scheduler for that purpose. The scheduler configuration sits in an initializer file like so:
scheduler = Rufus::Scheduler.start_new
scheduler.every('1d') do
puts "I run once every day"
end
scheduler.every '3h' do
puts "I run every 3 hours"
end

Monitoring ROR server (thin or mongrel) for resources and availability in WINDOWS and re-spawn

First thing I would like to say is, i know deploying ror applications in windows is not recommended, but in this case i have no choice due to some client restrictions.
I am looking for a tool like Upstart for windows which will moniter my instance of Thin or Mongrel and will 're-spawn' in case of crashes or availability.
Now I looked around quite a bit and most solutions like UpStart, or Passenger server are only available for Unix environments.
Any known tools for windows? and how to use them?
I am also open to any alternative ror servers for windows that can do this automatically like passenger does.
Thanks
Shaunak
Maybe a bat script as a scheduled task to run wmic process, scan to find Mongrel, and if it's not found to run it?
Sorry, I'd do it in bash, or I'd have a code example for you.
This would also make a good python script, in my opinion.

What requirments are necessary for a webhoster to host Diaspora*

What do I need to get from a webhoster if I want to host my own Diaspora* seed? Do I just need some webspace with ruby on rails capabilities? I suppose it uses Ruby On Rails SOAP for communication between seeds? If so what is needed for this?
According to the README on GitHub, you need Ruby, MongoDB, OpenSSL, ImageMagick, Git, RubyGems, and Bundler... so any decent shared hosting that allows you to build things in your homedir and run custom long-running processes should do the trick.
(Decent because the non-decent ones may omit Git or ImageMagick and not give you the resources to install them yourself. Long-running processes for MongoDB and the Diaspora app server.)
WebFaction, for example, should meet those needs but Dreamhost may not unless the Diaspora app server can somehow be managed by FastCGI to work around their long-running process killer. (Dreamhost apparently supports MongoDB, so that would be exempt from the killer)
Seriously though, I'd recommend waiting. Diaspora was just released. It's still in development and, if anything, probably best to be experimented with on your home PC for at least a few more months.
In general you need a server which allows you to run background processes, as diaspora* uses Sidekiq to process background jobs.
Any VPS Linux server for example with a recommended minimum 1GB should do fine for a small user base.
See: https://wiki.diasporafoundation.org/FAQ_for_pod_maintainers#What_are_the_general_system_requirements.3F

modrails - rogue ruby processes consuming 100% cpu

I'm having ruby instances from mod_rails go "rogue" -- these processes are no longer listed in passenger-status and utilize 100% cpu.
Other than installing god/monit to kill the instance, can anyone give me some advice on how to prevent this? I haven't been able to find anything in the logs that helps.
If you're using Linux, you can install the "strace" utility to see what the Ruby process is doing that's consuming all the CPU. That will give you a good low-level view. It should be available in your package manager. Then you can:
$ sudo strace -p 22710
Process 22710 attached - interrupt to quit
...lots of stuff...
(press Ctrl+C)
Then, if you want to stop the process in the middle and dump a stack trace, you can follow the guide on using GDB in Ruby at http://eigenclass.org/hiki.rb?ruby+live+process+introspection, specifically doing:
gdb --pid=(ruby process)
session-ruby
stdout_redirect
(in other terminal) tail -f /tmp/ruby_debug.(pid)
eval "caller"
You can also use the ruby-debug Gem to remotely connect to debug sockets you open up, described in http://duckpunching.com/passenger-mod_rails-for-development-now-with-debugger
There also seems to be a project on Github concerned with debugging Passenger instances that looks interesting, but the documentation is lacking:
http://github.com/ddollar/socket-debugger/tree/master
I had a ruby process related to Phusion Passenger, which consumed lots of CPU, even though it should have been idle.
The problem went away after I ran
date -s "`date`"
as suggested in this thread. (That was on Debian Squeeze)
Apparently, the problem was related to a leap second, and could affect many other applications like MySQL, Java, etc. More info in this thread on lklm.
We saw something similar to this with very long running SQL queries.
MySQL would kill the queries because they exceeded the long running limit and the thread never realized that the query was dead.
You may want to check the database logs.
This is a recurring issue with passenger. I've seen this problem many times helping people that ran ruby on rails with passenger. I don't have a fix but you might want to try this http://www.modrails.com/documentation/Users%20guide%20Apache.html#debugging_frozen

Resources