Skip to content

Instantly share code, notes, and snippets.

@denniskuczynski
Created June 21, 2012 20:12
Show Gist options
  • Save denniskuczynski/2968251 to your computer and use it in GitHub Desktop.
Save denniskuczynski/2968251 to your computer and use it in GitHub Desktop.
Example Monit Configuration ERB file to leverage Ruby for Config
<% PWD = ENV["PWD"] %>
<% PID_DIR = '/usr/local/var/run' %>
<%
ADDITIONAL = ''
if ENV['RVM']
ADDITIONAL = "export PATH=#{ENV['PATH']} && export GEM_HOME=#{ENV['GEM_HOME']} && export GEM_PATH=#{ENV['GEM_PATH']} && export HOME=#{ENV['HOME']} && "
end
%>
#
# ENVIRONMENT SETS
#
set daemon 120 # Poll every two minutes
set logfile <%=PID_DIR%>/monit.log
set mailserver smtp.gmail.com port 587
username "[email protected]" password "spammy" using tlsv1, www.example.com
with timeout 15 seconds
set alert [email protected]
set httpd port 2812 address localhost
allow localhost
allow admin:monit
#
# PROCESS CHECKS
#
# Check for daemonized Redis
check process redis with pidfile <%=PID_DIR%>/redis.pid
start program = "/usr/local/bin/redis-server /usr/local/etc/redis.conf"
stop program = "/usr/local/bin/redis-cli -p 6379 shutdown"
group redis
# Check for Ruby sidekiq worker process
check process sidekiq_worker with pidfile "<%=PID_DIR%>/sidekiq-worker.pid"
start program = "/bin/bash -c '<%= ADDITIONAL %> cd <%= PWD %> && nohup bundle exec sidekiq -v -e production -P <%=PID_DIR%>/sidekiq-worker.pid -q * -c 25 >> <%=PID_DIR%>/sidekiq.log 2>&1'" with timeout 90 seconds
stop program = "/bin/bash -c '<%= ADDITIONAL %> cd <%= PWD %> && nohup bundle exec sidekiqctl stop <%=PID_DIR%>/sidekiq-worker.pid 60 >> <%=PID_DIR%>/sidekiq.log 2>&1'" with timeout 90 seconds
group sidekiq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment