|
# monitrc template file |
|
set daemon 60 |
|
set pidfile <%= install_path %>/pids/monit.pid |
|
# gmail or google apps account |
|
|
|
<% if gmail_username && gmail_password %> |
|
set mailserver smtp.gmail.com port 587 |
|
username "<%= gmail_username %>" password "<%= gmail_password %>" |
|
using tlsv1 with timeout 60 seconds |
|
<% end %> |
|
set mail-format { from: <%= email %> } |
|
set alert <%= email %> with reminder on 10 cycles |
|
# Monit web panel |
|
set httpd port 44102 |
|
allow admin:"password" |
|
|
|
# tor |
|
<% tors_count.times.each do |c| %> |
|
check process tor<%= c %> with pidfile <%= install_path %>/pids/tor<%= c %>.pid |
|
group proxy |
|
start program = "/bin/sh -c '<%= tor_path %> --RunAsDaemon 1 --CookieAuthentication 0 --PidFile <%= install_path %>/pids/tor<%= c %>.pid --SocksPort <%= tor_base_port + c %> --DataDirectory <%= install_path %>/caches/tor<%= c %>'" as uid <%= user %> and gid <%= user %> |
|
stop program = "/bin/sh -c '/bin/kill -s SIGTERM `cat <%= install_path %>/pids/tor<%= c %>.pid` && rm \"<%= install_path %>/pids/tor<%= c %>.pid\"'" as uid <%= user %> and gid <%= user %> |
|
if mem > 32 MB for 3 cycles then restart |
|
if cpu > 30% for 5 cycles then restart |
|
<% end %> |
|
|
|
# delegated |
|
<% tors_count.times.each do |c| %> |
|
check process delegated<%= c %> with pidfile <%= install_path %>/pids/delegated<%= c %>.pid |
|
group proxy |
|
start program = "/bin/sh -c '<%= delegated_path %> -P<%= delegated_base_port + c %> SERVER=http SOCKS=localhost:<%= tor_base_port + c %> PIDFILE=<%= install_path %>/pids/delegated<%= c %>.pid LOGFILE=<%= install_path %>/log/delegated.log ADMIN=<%= email %>'" as uid <%= user %> and gid <%= user %> |
|
stop program = "/bin/sh -c '/bin/kill -s SIGTERM `cat <%= install_path %>/pids/delegated<%= c %>.pid` && rm \"<%= install_path %>/pids/delegated<%= c %>.pid\"'" as uid <%= user %> and gid <%= user %> |
|
if mem > 8 MB for 3 cycles then restart |
|
if cpu > 30% for 5 cycles then restart |
|
depends on tor<%= c %> |
|
<% end %> |
|
|
|
# haproxy |
|
check process haproxy with pidfile <%= install_path %>/pids/haproxy.pid |
|
group proxy |
|
start program = "/bin/sh -c '<%= haproxy_path %> -f <%= install_path %>/etc/haproxy.cfg -p <%= install_path %>/pids/haproxy.pid'" as uid <%= user %> and gid <%= user %> |
|
stop program = "/bin/sh -c '/bin/kill `cat <%= install_path %>/pids/haproxy.pid` && rm \"<%= install_path %>/pids/haproxy.pid\"'" as uid <%= user %> and gid <%= user %> |
|
if mem > 8 MB for 3 cycles then restart |
|
if cpu > 40% for 5 cycles then restart |
|
depends on <%= tors_count.times.map{ |c| "delegated#{c}" }.join(', ') %> |
|
|
|
# monitrc to restart monit itself |
|
check file monitrc path <%= install_path %>/etc/monitrc |
|
if changed md5 checksum |
|
then exec "<%= monit_path %> reload" |
mattes commentedApr 11, 2014
I wrote a little optparser wrapper to make this setup even more easier. https://github.com/mattes/rotating_proxy_setup