Skip to content

Instantly share code, notes, and snippets.

@mrrooijen mrrooijen/monit.rc

forked from anonymous/file1.ab
Created May 7, 2011
What would you like to do?
RVM + Monit
# thin
# assuming there's an appropriate .rvmrc in /path_to_rails_app/current
cd rails_app/current
gem install thin
rvm wrapper your_ruby@your_gemset your_app_name thin
# now we can use your_app_name_thin in Monit scripts
# /etc/monit.d
# repeat for each port identified in config/thin.yml
# in this example port = 8000
# username and password is that of the account your_app runs in
check process thin-8000 with pidfile /path_to_rails_app/current/tmp/pids/
start program = "/path_to_your_app_name_thin -u user_name -g group -C /path_to_rails_app/current/config/thin.yml start --only 8000"
stop program = "/path_to_your_app_name_thin -u user_name -g group -C /path_to_rails_app/current/config/thin.yml stop --only 8000"
if totalmem is greater than 120.0 MB for 5 cycles then restart # eating up memory?
if cpu is greater than 50% for 2 cycles then alert # send an email to admin
if cpu is greater than 80% for 3 cycles then restart # hung process?
if loadavg(5min) greater than 10 for 8 cycles then restart # bad, bad, bad
if 3 restarts within 5 cycles then timeout # something is wrong, call the sys-admin
group thin
# assuming Capistrano deployment, this in deploy.rb
set :thin_config, "#{deploy_to}/current/config/thin.yml"
namespace :deploy do
task :start do
run "your_app_name_thin start -u user_name -g password -C #{thin_config}"
task :stop do
run "your_app_name_thin stop -u user_name -g password -C #{thin_config}"
task :restart, :roles => :app, :except => { :no_release => true } do
# to let monit start these, remove start, but I prefer to be explicit
# and not have to wait for monit to detect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.