Log inSign up

Keep services alive on your VPS with Monit checks

Install the monit package (from EPEL on Rocky and Alma), drop one small check file per service into the include folder and run sudo monit -t followed by sudo monit reload. From then on Monit polls every cycle, restarts a process that died or stopped answering on its port, and raises an alert when disk, memory or load cross the limits you set.

Topic: Monitoring and logs · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

Why add Monit when systemd already restarts units?

Monit tests behaviour, not only existence. A systemd unit with Restart=on-failure brings a crashed process back, yet it cannot tell that Nginx is running but returns errors, that PHP-FPM stopped accepting connections, or that the root filesystem is at 95 percent. Monit runs those probes on a schedule and acts on the answer: restart, stop, run a script or send an alert.

It is a single small daemon written in C with a plain text configuration, so it fits even on a 1 GB plan next to the services it protects. Treat it as the layer between the basic restarts covered in running an app as a systemd service and a full monitoring stack such as Zabbix. For host wide CPU and traffic history, the Usage graphs tab in the console already keeps charts outside the server.

Which packages install Monit on each distribution?

Ubuntu and Debian ship Monit in their main archives. Rocky Linux 9 and AlmaLinux 9 get it from EPEL, which you enable first.

# Ubuntu 24.04 / 22.04, Debian 12 / 13
sudo apt update
sudo apt install -y monit

# Rocky Linux 9, AlmaLinux 9
sudo dnf install -y epel-release
sudo dnf install -y monit
sudo systemctl enable --now monit

Confirm the version and the service state:

monit -V
systemctl status monit --no-pager

The main file lives at /etc/monit/monitrc on Ubuntu and Debian and at /etc/monitrc on Rocky and Alma. Both include a folder for your own checks: /etc/monit/conf.d/ on the Debian family and /etc/monit.d/ on the Red Hat family. Keep the stock file mostly untouched and put every service check in that folder, one file per service, so upgrades never fight with your edits.

How do I set the polling cycle and turn on the local web interface?

Two lines near the top of the main file control the rhythm: set daemon is the cycle length in seconds and with start delay gives services time to boot before the first test.

set daemon 30
    with start delay 60

The status page and the monit status command both talk to an embedded HTTP server. Bind it to loopback only so nothing outside the VPS can reach it:

set httpd port 2812 and
    use address 127.0.0.1
    allow 127.0.0.1
    allow deploy:ChangeThisLongSecret

Monit refuses to start when the control file is readable by others, because it may hold passwords. Fix the mode if you copied it around:

sudo chmod 600 /etc/monit/monitrc    # Ubuntu, Debian
sudo chmod 600 /etc/monitrc          # Rocky, Alma

To see the page from your laptop, open a tunnel with ssh -N -L 2812:127.0.0.1:2812 deploy@198.51.100.24 and browse to http://127.0.0.1:2812. If you ever need it on a hostname, put it behind a TLS reverse proxy with basic auth as shown in the Caddy HTTPS tutorial instead of opening port 2812.

What does a check that restarts Nginx look like?

A process check names the PID file, the commands to start and stop, and the tests that count as failure. Save this as /etc/monit/conf.d/nginx (or /etc/monit.d/nginx):

check process nginx with pidfile /run/nginx.pid
    start program = "/usr/bin/systemctl start nginx"
    stop program  = "/usr/bin/systemctl stop nginx"
    if failed host 127.0.0.1 port 80 protocol http
        request "/" with timeout 10 seconds
        for 2 cycles
    then restart
    if cpu usage > 90% for 5 cycles then alert
    if 4 restarts within 10 cycles then unmonitor

Reading it top to bottom: Monit asks Nginx for the front page every cycle, and two failures in a row trigger a restart through systemctl. A sustained CPU spike only raises an alert. The last rule stops a restart loop: after four restarts in ten cycles Monit gives up and marks the service as unmonitored, which keeps a broken config from hammering the box. Using systemctl for start and stop keeps systemd as the single owner of the process.

The same pattern works for other daemons. For a database, test the socket or the TCP port with the matching protocol, for example if failed unixsocket /run/mysqld/mysqld.sock protocol mysql then restart.

How do I watch disk space, memory and load?

System and filesystem checks catch the slow problems that never crash a process. Create /etc/monit/conf.d/host:

check system $HOST
    if loadavg (5min) > 3 for 4 cycles then alert
    if memory usage > 85% for 4 cycles then alert
    if swap usage > 50% then alert
    if cpu usage (wait) > 30% for 4 cycles then alert

check filesystem rootfs with path /
    if space usage > 85% then alert
    if inode usage > 85% then alert

check file syslog with path /var/log/syslog
    if timestamp > 30 minutes then alert

Pick the load threshold from your plan size: on a 2 vCPU server a five minute load above 3 means work is queuing. The file check is handy for apps that write a heartbeat file; on Rocky and Alma point it at /var/log/messages instead, and on Debian 12 or 13 (no rsyslog by default) aim it at a file your own app touches. When disk alerts fire, the guide on finding what fills the disk walks through the cleanup.

How do alerts reach me by email?

Monit sends mail itself through any SMTP server you configure. Outgoing port 25 may be restricted, so do not plan on direct delivery without first asking support with a ticket; an authenticated relay on port 587 is the dependable route:

set mailserver smtp.example.net port 587
    username "alerts@example.net" password "RelayPassword"
    using tls

set mail-format { from: monit@example.net }
set alert ops@example.net not on { instance, action }

The not on filter skips the routine messages Monit sends when it starts or when you act on a service, so the inbox only gets real events. To route alerts somewhere else, use an exec action in a check, for example then exec "/usr/local/bin/notify.sh", and post to a chat webhook from that script.

How do I validate, reload and operate Monit day to day?

Always run the syntax test before a reload; it names the file and line of any mistake.

sudo monit -t
sudo monit reload
sudo monit summary
sudo monit status nginx

Planned maintenance is the one moment Monit can get in your way, because it will restart a service you stopped on purpose. Pause the check first and resume it afterwards:

sudo monit unmonitor nginx
# ... edit configs, run upgrades ...
sudo monit monitor nginx

To prove that self healing works, kill the process and watch the log:

sudo pkill -9 nginx
sudo tail -f /var/log/monit.log

Within one or two cycles you should see a line saying the process is not running, followed by a start action and a success message. sudo monit status nginx then reports the new PID and uptime.

What usually goes wrong and how do I fix it?

  • Monit exits at boot with a permission error: the control file must be mode 600 and owned by root.
  • Checks show "Does not exist" for a running service: the PID file path is wrong. Find the real one with systemctl show -p PIDFile nginx, or switch to check process nginx matching "nginx: master".
  • Restart loops: the start program returns before the service is ready. Add with timeout 60 seconds to the start line and keep a restart limit rule.
  • No mail arrives: look for SMTP errors in /var/log/monit.log, test the relay credentials and check the sender address is allowed by the relay.
  • Status command fails: the httpd block is missing or bound to a different address than the CLI uses; keep use address 127.0.0.1 with allow 127.0.0.1.

Upgrades come through the normal package manager. After a major distribution upgrade, run monit -t again, because rare syntax changes between releases are reported there.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-1Monit plus one small web service1 vCPU, 1 GB RAM, 25 GB NVMe$3.60/mo$43.20 for 12 months
A1-2web server, PHP-FPM and a database under watch1 vCPU, 2 GB RAM, 50 GB NVMe$7.20/mo$43.20 for 6 months

Questions about Monit for self-healing services

Does Monit replace a full monitoring system?

No. It is a local watchdog that acts on one host. For history, dashboards and many servers, pair it with Prometheus, Netdata or Zabbix and let Monit handle the quick restarts.

How much memory does Monit use?

Usually only a few megabytes of RAM. The cost grows slightly with the number of checks and the cycle length, but it stays small enough for the smallest plans.

Should Monit and systemd both restart the same service?

It works, but give them different jobs. Let systemd handle plain crashes with Restart=on-failure, and let Monit handle health tests such as HTTP answers or socket responses, starting and stopping through systemctl so both agree on the state.

Can Monit check a remote website?

Yes. A check host block with if failed port 443 protocol https tests any address. For a public status page with history, Uptime Kuma is easier to share.

Where do I see why Monit restarted something?

In /var/log/monit.log. Each event shows the check name, the failed test and the action taken, and sudo monit status keeps the last result for each check.

Is it safe to expose port 2812?

Keep it on 127.0.0.1 and use an SSH tunnel. If remote access is truly needed, publish it through a reverse proxy with HTTPS and a strong password, and keep the firewall closed for 2812.