How to use monit to automatically restart Usermin on port 20000 if it fails

What is Monit?

Monit is a free and open-source process monitoring utility for Unix and Linux systems. It provides a way to monitor various aspects of a system, including system processes, services, files, directories, and devices, to ensure they are functioning as expected. Monit can automatically restart failed processes, alert administrators of system issues via email or other methods, and provide detailed logs of monitored activities. With Monit, system administrators can proactively detect and resolve problems before they become major issues, ensuring the stability and reliability of their systems.

How to use Monit to monitor Usermin

At times Usermin fails when accessing the front-end. The service appears to be running in the OS, but the port is closed and Usermin isn’t available. Furthermore no information as to why it failed is available in the log files, located here:

tail /var/usermin/miniserv.error
tail /var/usermin/miniserv.log

This can happen on server with as little RAM as 2GB, and as much as 16 GB. The stoppages are random, but only encountered when accessing Usermin in the browser.

One way of alleviate the pain is to use Monit to monitor port 20000, and then restart Usermin if it’s not available.

The instructions on how to do this is:

apt install monit
vi /etc/monit/conf-available/usermin

Create this file in /etc/monit/conf-available/:

check host usermin with address 127.0.0.1
start program = "/bin/systemctl start usermin"
stop program = "/bin/systemctl stop usermin"
if failed port 20000 then restart
if 5 restarts within 5 cycles then timeout
alert [email protected]
set mailserver 127.0.0.1

Now link it:

ln -s /etc/monit/conf-available/usermin /etc/monit/conf-enabled/

Now check it and reload it:

monit -t
systemctl reload monit

Here is a typical log event:

tail /var/log/monit.log

[SAST Dec 30 08:13:53] error : 'usermin' failed protocol test [DEFAULT] at [127.0.0.1]:20000 [TCP/IP] -- Connection refused
[SAST Dec 30 08:13:53] info : 'usermin' trying to restart
[SAST Dec 30 08:13:53] info : 'usermin' stop: '/bin/systemctl stop usermin'
[SAST Dec 30 08:13:54] info : 'usermin' start: '/bin/systemctl start usermin'
[SAST Dec 30 08:15:56] info : 'usermin' connection succeeded to [127.0.0.1]:20000 [TCP/IP]

What alternatives exist for monit?

Question: Monit seems quite complicated. Isn’t there another way?

Answer: If you’re using Webmin you can also monitor processes using Webmin. See here.

References

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top