User Tools

Site Tools


doc:appunti:linux:sa:monit

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
doc:appunti:linux:sa:monit [2012/10/22 11:34] – created niccolodoc:appunti:linux:sa:monit [2016/04/26 09:22] (current) – [Interruzione del monitoraggio] niccolo
Line 26: Line 26:
  check process spamd with pidfile /var/run/spamd.pid  check process spamd with pidfile /var/run/spamd.pid
    group spamd    group spamd
-   start program = "/etc/init.d/spamassassin start"+   start program = "/etc/init.d/spamassassin start" 
    stop  program = "/etc/init.d/spamassassin stop"    stop  program = "/etc/init.d/spamassassin stop"
    if 5 restarts within 5 cycles then timeout    if 5 restarts within 5 cycles then timeout
Line 48: Line 48:
    if failed gid root then unmonitor    if failed gid root then unmonitor
 </file> </file>
 +
 +**Attenzione:** Monit esegue un ciclo di test ogni due minuti (impostazione predefinita Debian, vedi **''set daemon 120''** in ''/etc/monit/monitrc''). Quando deve riavviare un servizio attende fino a 30 secondi per lo stop e lo start dello stesso, è possibile modificare tale tempo con l'opzione ''with timeout''. In base a questi parametri bisogna aggiustare il timeout (cioè quando scatta l'interruzione del monitoraggio) dopo un certo numero di restart avvenuti in un certo numero di cicli (''if 5 restarts within 5 cycles then timeout''). In caso contrario si ottiene
 +
 +<code>
 +...
 +[CET Mar 28 16:53:40] info     : 'spamd' start: /etc/init.d/spamassassin
 +[CET Mar 28 16:54:11] error    : 'spamd' failed to start
 +[CET Mar 28 16:56:11] error    : 'spamd' process is not running
 +[CET Mar 28 16:56:11] info     : 'spamd' trying to restart
 +[CET Mar 28 16:56:11] info     : 'spamd' start: /etc/init.d/spamassassin
 +[CET Mar 28 16:56:43] error    : 'spamd' failed to start
 +[CET Mar 28 16:58:43] error    : 'spamd' service restarted 5 times within 5 cycles(s) - unmonitor
 +</code>
 +
 +Ecco quindi una configurazione che insiste più a lungo per riavviare il servizio e che esegue una azione drastica (**''killall -9''**) se il restart fallisce per 4 volte. Attenzione che il ''killall'' deve uccidere sia i processi chiamati **''spamd''** che i processi chiamati **''spamd child''**:
 +
 +<file>
 +   ...
 +   start program = "/etc/init.d/spamassassin start" 
 +   stop  program = "/etc/init.d/spamassassin stop" with timeout 60 seconds
 +   if 4 restarts within 4 cycles then exec "/usr/bin/killall -9 --regexp 'spamd\b.*'"
 +   if 10 restarts within 10 cycles then timeout
 +   ...
 +</file>
 +
  
 Poi alcuni parametri sono stati aggiustati in **''/etc/monit/monitrc''**: Poi alcuni parametri sono stati aggiustati in **''/etc/monit/monitrc''**:
Line 54: Line 79:
   set daemon 120            # check services at 2-minute intervals   set daemon 120            # check services at 2-minute intervals
   with start delay 240      # optional: delay the first check by 4-minutes (by    with start delay 240      # optional: delay the first check by 4-minutes (by 
 +
 +  set mailserver localhost
 +  
 +  set mail-format { from: sistema@texnet.it }  # Set custom From: mail header
 +
 +  set alert support@texnet.it                  # receive all alerts
  
   set httpd port 2812 and   set httpd port 2812 and
     use address 62.48.51.60  # only accept connection from localhost     use address 62.48.51.60  # only accept connection from localhost
-    allow 62.48.51.8         # allow localhost to connect to the server and+    allow 62.48.51.60        # allow localhost to connect to the server and 
 +    allow 62.48.51.8         # allow a remote host to connect to the server and
     allow admin:MySecret     # require user 'admin' with password 'monit'     allow admin:MySecret     # require user 'admin' with password 'monit'
     allow @monit             # allow users of group 'monit' to connect (rw)     allow @monit             # allow users of group 'monit' to connect (rw)
     allow @users readonly    # allow users of group 'users' to connect readonly     allow @users readonly    # allow users of group 'users' to connect readonly
 </file> </file>
 +
 +===== Interruzione del monitoraggio =====
 +
 +Se un processo monitorato si blocca, viene tentato il suo riavvio. Potrebbe capitare che il processo non riesca a partire nei tempi previsti, ad esempio ''spamd'' che non ha rilasciato il socket:
 +
 +<code>
 +spamd[8042]: spamd: could not create INET socket on 127.0.0.1:783: Address already in use
 +</code>
 +
 +In tal caso il processo non viene più sottoposto a monitoraggio, neanche dopo un reboot. Si può verificare lo stato con:
 +
 +<code>
 +monit summary
 +</code>
 +
 +Per riattivare il monitoraggio:
 +
 +<code>
 +monit monitor spamd
 +</code>
 +
 +Questo comando funziona solo se è stata attivata la funzione integrata di server http (vedi configurazione ''set httpd'' sopra). Altrimenti come si fa ad attivare un monitoraggio disabilitato? FIXME
doc/appunti/linux/sa/monit.txt · Last modified: 2016/04/26 09:22 by niccolo