Monit can help ensure your Rails app stays up and running smoothly. Here I show how to set it up, receive alerts, and keep tabs on it through a web interface.
Foreman has a major flaw that makes it a non-starter for me: it can't handle different commands for starting and stopping a service. It also doesn't allow for different environments without using a wrapper shell script.
Guys, I ran into an issue with Monit + Resque + rbenv setup. My Resque workers fail to start with Monit saying rbenv: not found, but the same command works fine if I run it directly in console under user deployer. Have someone managed to set up monit to monitor Resque workers? Any ideas?
Your user "deployer" has all the lovely rbenv PATH stuff in place and working.
If that is all working, I posted an answer to your SO question that might help that involves changing the way you specify what user the start command runs as.
Hope that helps.
Oh, also su to your "deployer" user and run the magical "rbenv rehash" command? Dunno, just a thought.
Sorry, the problem with the above solution is that both the parent and child processes will write out their pid to the worker's pid file. We just want the child so change it to:
ruby
after_fork do |server, worker|
ifProcess.ppid > 1# Not the daemon
child_pid = server.config[:pid].sub('.pid', ".#{worker.nr}.pid")
File.open(child_pid, "wb") {|f| f << Process.pid }
endend
Has anyone got a monit template for Sidekiq and/or Redis?
I'm having a bit of a hard time setting the pidfiles up correctly with Unicorn Zero Downtime Deployments. This is where I'm at right now https://gist.github.com/3818705
I've noticed that during deployments, monit will sometimes see that unicorn, sidekiq etc have no pidfiles so will try to start them before the deploy is completed. Does anyone have a solution for this?
I'm thinking of writing a capistrano lockfile when the deploy is started and removing it when finished, then monit can skip its checks for the affected services if the lockfile exists.
If you only run a single server, you have to use a third-party service to monitor your server. Because if your server goes down, Monit will go down with it.
I made a Heroku Buildpack for Monit: https://github.com/k33l0r/monit-buildpack
Of course Heroku limits what you can do with it, but at the very least you can use it to monitor your sites and external services…
Thank you!
Monit is cool, but Ubuntu already provide similar monitor features via UpStart and other Linux distro are switching to systemd.
What do you think about the foreman approch, that can be used on heroku and standalone? http://grigio.org/dns_setup_and_procfile_local_development_and_deployment?rc
Foreman already export the ""keep-alive script" towards monit or upstart http://ddollar.github.com/foreman/#UPSTART-EXPORT
Using Foreman with Upstart is the way to go these days. This is a decent post on it.
Foreman has a major flaw that makes it a non-starter for me: it can't handle different commands for starting and stopping a service. It also doesn't allow for different environments without using a wrapper shell script.
Guys, I ran into an issue with Monit + Resque + rbenv setup. My Resque workers fail to start with Monit saying
rbenv: not found
, but the same command works fine if I run it directly in console under user deployer. Have someone managed to set up monit to monitor Resque workers? Any ideas?I've posted some more info here: http://stackoverflow.com/questions/12094311/managing-resque-workers-with-monit-on-rbenv-setup
Two things to make sure:
Hope that helps.
Oh, also su to your "deployer" user and run the magical "rbenv rehash" command? Dunno, just a thought.
Hi, monit doesn't want to monitor workers, that's very strange, my app is working and if I do ps aux | grep unicorn I can see them :
deployer 19705 1.7 10.0 59404 50972 ? Sl 02:59 0:06 unicorn master -D -c /home/deployer/apps/blog/shared/config/unicorn.rb -E production
deployer 19709 0.0 10.5 65484 53848 ? Sl 02:59 0:00 unicorn worker[0] -D -c /home/deployer/apps/blog/shared/config/unicorn.rb -E production
deployer 19712 0.0 10.5 65484 53824 ? Sl 02:59 0:00 unicorn worker[1] -D -c /home/deployer/apps/blog/shared/config/unicorn.rb -E production
However /home/deployer/apps/blog/shared/pids contains only unicorn.pid and no unicorn.0.pid
Also if I try to find them with find (sudo find / -name "*.pid") :
/home/deployer/apps/blog/shared/pids/unicorn.pid
/run/monit.pid
/run/nginx.pid
/run/ntpd.pid
/run/sshd.pid
/run/fail2ban/fail2ban.pid
/run/upstart-udev-bridge.pid
/run/atd.pid
/run/crond.pid
/run/rsyslogd.pid
/run/dhclient.eth0.pid
/run/upstart-socket-bridge.pid
Only the master appears...
Do you have any idea about it plz ?
Add this to the bottom of your unicorn.rb
so that each unicorn worker creates its own PID. See this post for more info.
Sorry, the problem with the above solution is that both the parent and child processes will write out their pid to the worker's pid file. We just want the child so change it to:
Has anyone got a monit template for Sidekiq and/or Redis?
I'm having a bit of a hard time setting the pidfiles up correctly with Unicorn Zero Downtime Deployments. This is where I'm at right now https://gist.github.com/3818705
Thanks
Hi John,
I'm in the same boat. Did you ever get this working?
thx Ryan, so useful for me now.
Has anyone have an template for monitoring Passenger workers? I'm also finding so hard to include pid-file into my.cnf using MySQL. Any ideas?
Thanks all!!
I'm getting this error when running cap monit:setup
/ruby-1.9.3-p327/gems/capistrano-2.14.1/lib/capistrano/configuration/variables.rb:122:in
method_missing_with_variables': undefined method
template' for #Capistrano::Configuration:0x8ce5a24 (NoMethodError)I'm getting the same thing.. not sure what the deal is! Unless it has something to do with me not using the "templates" folder?...
I ran into this same issue...
template is a method that is defined in templates/base.rb
Here's a sudo template helper method to keep your code... DRY
Put it in
config/recipes/base.rb
I've noticed that during deployments, monit will sometimes see that unicorn, sidekiq etc have no pidfiles so will try to start them before the deploy is completed. Does anyone have a solution for this?
I'm thinking of writing a capistrano lockfile when the deploy is started and removing it when finished, then monit can skip its checks for the affected services if the lockfile exists.
Why not just use Capistrano for deployment, and use a before stop hook and first stop monit, then after start, start monit?
Thanks for the suggestion Allen. This fixed my unicorn deploy woes and seems to be pretty clean.
I added these tasks:
And then these hooks:
If you only run a single server, you have to use a third-party service to monitor your server. Because if your server goes down, Monit will go down with it.
Here is an excellent article on monitoring : Monitoring and Maintaining Your Server