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

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]

References

Share this article

Leave a Reply

Your email address will not be published.

Scroll to Top