Monit Reload Behavior: Does Configuration Reload Trigger Service Restarts?


2 views

When executing monit reload on an Ubuntu server running Monit 5.4, we observe that monitored services (specifically Tomcat 7 in this case) are being restarted, despite the official documentation stating that reload should only reinitialize the daemon configuration.

$ monit reload
Reinitializing monit daemon

The current monitoring setup for Tomcat includes these critical directives:

check process tomcat7 with pidfile /var/run/tomcat7.pid
start program = "/etc/init.d/tomcat7 restart"
stop program = "/etc/init.d/tomcat7 stop"

if failed port 80 and protocol http
  then restart

While the documentation suggests reload shouldn't affect services, there are several scenarios where restart might occur:

  • PID file validation during reload finds discrepancies
  • Changed resource limits in the new configuration
  • Modified check conditions that immediately trigger actions

To prevent unwanted restarts during configuration reloads:

# Safeguard against unnecessary restarts
check process tomcat7 with pidfile /var/run/tomcat7.pid
  matching "tomcat"
  start program = "/etc/init.d/tomcat7 start" with timeout 60 seconds
  stop program = "/etc/init.d/tomcat7 stop" with timeout 60 seconds
  
  # Add stabilization period
  if changed pid then alert
  if 3 restarts within 5 cycles then unmonitor

For critical production environments, consider:

  1. Using monit validate to check configuration before reload
  2. Implementing configuration changes through version control
  3. Testing changes in a staging environment first

To investigate reload behavior:

# Increase verbosity
$ monit -vv reload

# Check logs immediately after reload
$ tail -f /var/log/monit.log

Look for entries containing "Executing" or "Action" in the logs to identify what triggers the restart.


When working with Monit 5.4 on Ubuntu servers, many administrators notice an unexpected behavior: the monit reload command appears to restart monitored services like Tomcat 7, despite documentation suggesting it should only reload the configuration.

The official documentation states:

reload - Reinitialize a running Monit daemon, the daemon will reread its configuration, 
close and reopen log files.

However, in practice with the following Tomcat configuration:

check process tomcat7 with pidfile /var/run/tomcat7.pid
start program = "/etc/init.d/tomcat7 restart"
stop program = "/etc/init.d/tomcat7 stop"

if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart

if failed port 80 and protocol http
  then restart
if 5 restarts within 5 cycles then timeout

The service restarts occur because of how Monit handles PID file validation during reload.

Monit performs these steps during reload:

  1. Closes all existing connections and files
  2. Revalidates all monitored processes against their PID files
  3. If the PID file check fails (common during quick reloads), Monit considers the process dead
  4. Executes the start program defined in your configuration

To modify configuration without triggering restarts:

# Alternative approach that prevents restart on reload
check process tomcat7 matching "/usr/share/tomcat7"
start program = "/etc/init.d/tomcat7 start"
stop program = "/etc/init.d/tomcat7 stop"

# More stable monitoring conditions
if failed port 80 protocol http
  with timeout 5 seconds
  for 3 cycles
  then alert

if 3 restarts within 5 cycles then unmonitor

For services where PID files might cause issues:

check process nginx matching "nginx: worker"
  with pidfile /var/run/nginx.pid
  every 2 cycles
  start program = "/etc/init.d/nginx start"
  stop program = "/etc/init.d/nginx stop"

Note that this behavior has evolved across versions:

  • 5.4: Aggressive restart behavior
  • 5.8+: More tolerant PID validation
  • 5.25+: Added no action reload option

The most stable solution is to upgrade to newer Monit versions where available.