Monit can watch local processes and restart a service when it stops, which is useful when you run a small server without a separate process supervisor. It can also check basic network protocols, files, filesystems, and system resources. It is not a substitute for application health checks, logs, metrics, backups, or monitoring from outside the server.
This guide uses a systemd-based Debian or Ubuntu host for its example. Service names, executable paths, configuration locations, and PID files differ between distributions and packages, so confirm them on your server before enabling an automatic action.
What Monit can and cannot do
Monit runs checks on a schedule and can start, stop, or restart a service when a configured condition occurs. Its process checks answer questions such as “is the expected process running?” A separate protocol check can ask whether a local port responds.
Neither check necessarily proves that your application is working correctly. A web server process can be running while an application returns errors; a database process can be alive while queries are failing. Use a route that exercises the application or a database-level check when you need that assurance. Keep independent logs, metrics, backups, and an external uptime check: a local monitor cannot alert you if the whole host or its network connection is unavailable.
The Monit project describes its process, file, filesystem, network, and system checks. Monit also includes a lightweight HTTP(S) interface for viewing status and controlling monitored services.
Install Monit on Debian or Ubuntu
Install the distribution package and make sure Monit starts at boot:
sudo apt update
sudo apt install monit
sudo systemctl enable --now monit
Other Linux distributions provide Monit through their package managers too. Prefer a maintained distribution package unless you specifically need a newer upstream release. Check the package's service name and configuration layout before applying the example below.
Configure a process check
On Debian and Ubuntu, the main configuration is commonly /etc/monit/monitrc. Open it with an editor and add a service entry, or use a configuration directory only if the main file already includes it. Do not replace the package's whole configuration with a sample: it may contain important defaults and include statements.
Monit checks services on the interval configured by set daemon; use the package's existing interval unless you have a reason to change it. A shorter interval can detect a failure sooner but also runs checks and recovery actions more often.
This example checks the Nginx master process and asks systemd to start or stop its unit. The matching expression is a fallback for systems where you do not use a PID file; Monit's documentation recommends a PID file when one is available. The HTTP check is separate and sends an alert after repeated failures rather than restarting Nginx just because a port check failed.
check process nginx matching "nginx: master process"
start program = "/usr/bin/systemctl start nginx.service"
stop program = "/usr/bin/systemctl stop nginx.service"
if 3 restarts within 5 cycles then unmonitor
check host nginx-http with address 127.0.0.1
if failed port 80 protocol http for 3 cycles then alert
Confirm the systemctl path with command -v systemctl, and use the exact service unit installed on your host. For Apache, the unit may be apache2.service or httpd.service; MySQL packages may use mysql.service, mysqld.service, or mariadb.service. Do not assume one unit name or PID path works everywhere. See the systemctl manual for the service-management commands.
If you use a PID file instead, find the actual path in the service's configuration and use it in a check process <name> with pidfile <absolute-path> entry. If you use matching, test the expression before relying on it:
sudo monit procmatch "nginx: master process"
Monit selects the top-most matching parent process, so the expression should identify one unique service. A broad pattern can select the wrong process. For MySQL or Apache, check the installed package's process name, PID file, and systemd unit rather than copying the Nginx example.
The process check can start a missing service through its configured start method. A separate HTTP check tells you whether a local HTTP connection is responding; it does not verify your site's user-facing workflow. Replace the port and protocol with values appropriate for your service, and use an application health endpoint or a database-aware check if that is the signal you need.
Validate, start, and inspect
Before reloading Monit, check the control file for syntax errors:
sudo monit -t
If the output says the control file is valid, reload the running daemon and inspect its state:
sudo monit reload
sudo monit status
sudo monit summary
If Monit is not running yet, start it with your distribution's service manager, then check its status. When a check does not behave as expected, inspect sudo monit status, Monit's configured log destination, and the system service logs. Keep the restart and alert actions enabled only after confirming that the service command works when run by Monit.
Monit can send email alerts when you configure a mail server and an alert recipient. Its default behavior is to report a failure and a recovery; repeated reminders can be configured for a continuing incident. Test delivery and make sure someone can act on the alert before relying on it.
Avoid restart loops and secure the control interface
A restart may restore a process that exited, but it does not fix a bad deployment, exhausted disk, broken dependency, or failing database. The restart limit in the example stops repeated recovery attempts by unmonitoring the service after too many restarts. Monit then needs an administrator to investigate and re-enable it with sudo monit monitor nginx. Choose a limit that fits the service's normal startup and check interval.
Monit may run with privileges that allow it to manage system services. Protect its control file so only administrators can read or change it; Monit's manual requires restrictive permissions (no broader than 0700). Treat any scripts configured as start, stop, or recovery commands as privileged code.
The web interface can start, stop, and restart services. Do not expose its port directly to the public internet. If you need the interface, bind it to a private or loopback address, restrict allowed clients, use TLS and authentication, and access it through a VPN or SSH tunnel where practical. See the Monit documentation for the current configuration syntax, service checks, alert settings, and interface security options.
When to add another monitoring layer
Monit is a small, useful recovery tool for local processes. Add a separate application-level health check for real user workflows, metrics for trends and resource capacity, centralized logs for diagnosis, and tested backups for recovery. An external uptime check can detect host or network failures that Monit running on the same machine cannot report.
The Monit manual covers process checks, restart limits, protocol tests, alerts, and the HTTP interface in more detail.