Created
October 2, 2012 12:37
-
-
Save johnrees/3818705 to your computer and use it in GitHub Desktop.
Monit template files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
check process redis | |
start program = "/usr/bin/redis-server /etc/redis/redis.conf" | |
stop program = "/usr/bin/redis-cli -p 6379 shutdown" | |
with pidfile /var/run/redis.pid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /config/initializers/redis.rb | |
$redis = Redis.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
check process sidekiq with pidfile <%= sidekiq_pid %> | |
start program = "/etc/init.d/sidekiq_<%= application %> start" | |
stop program = "/etc/init.d/sidekiq_<%= application %> stop" | |
if totalmem is greater than 200 MB for 2 cycles then restart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
working_directory "<%= current_path %>" | |
pid "<%= unicorn_pid %>" | |
stderr_path "<%= unicorn_log %>" | |
stdout_path "<%= unicorn_log %>" | |
listen "/tmp/unicorn.<%= application %>.sock" | |
worker_processes <%= unicorn_workers %> | |
timeout 30 | |
preload_app true | |
before_fork do |server, worker| | |
# Disconnect since the database connection will not carry over | |
if defined? ActiveRecord::Base | |
ActiveRecord::Base.connection.disconnect! | |
end | |
# Quit the old unicorn process | |
old_pid = "#{server.config[:pid]}.oldbin" | |
if File.exists?(old_pid) && server.pid != old_pid | |
begin | |
Process.kill("QUIT", File.read(old_pid).to_i) | |
rescue Errno::ENOENT, Errno::ESRCH | |
# someone else did our job for us | |
end | |
end | |
end | |
after_fork do |server, worker| | |
# https://github.com/redis/redis-rb/blob/master/examples/unicorn/unicorn.rb | |
# Redis.current.quit | |
# https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting | |
# Sidekiq.configure_client do |config| | |
# config.redis = { size: 1 } | |
# end | |
# Start up the database connection again in the worker | |
if defined?(ActiveRecord::Base) | |
ActiveRecord::Base.establish_connection | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment