Why is it that, so often, a key bit of information is assumed by documentation writers?
I’ve had an issue for a while where monit will fail to start properly on boot. The issue is that with DietPi, it seems that the system boots too quickly and monit trys to create a network interface before the network is ready. Calling a systemctl restart monit
solves the problem but that is a pain to remember to do after every boot.
I started looking at systemd
solutions. There is an obvious one; use a timer file.
In theory you create a file with the extension .timer
and that then triggers the related service to start. Good in theory but I could not get it to work; the monit service just started straight off.
The clue is a small line here – “The .service
does not require an [Install]
section as it is the timer units that are enabled. ”
Off goes the light.
So the monit.service
file looks like this (note no install section)
1 2 3 4 5 6 7 8 9 |
[Unit] Description=Pro-active monitoring utility for unix systems After=network.target Documentation=man:monit(1) https://mmonit.com/wiki/Monit/HowTo [Service] Type=simple ExecStart= /usr/bin/monit -I -c /etc/monit/monitrc |
and the monit.timer
file looks like this
1 2 3 4 5 6 7 8 |
[Unit] Description=Runs monit after 1 minutes [Timer] OnBootSec=1min [Install] WantedBy=basic.target |
both reside in /lib/systemd/system/
To enable them you simply enable the timer systemctl enable monit.timer
One other thing I did and I’m not sure if it makes a difference, I removed the file /etc/init.d/monit
As a recap, a vanilla install of monit is simply apt-get install monit
.
To access the status, you need to setup the internal http server. Add a file /etc/monit/conf-enabled/monitconfig
with the contents;
1 2 3 |
set httpd port 2812 allow X.X.X.0/255.255.255.0 # allow local subnet only to connect and use address X.X.X.X # only accept connection from a specified IP if a fixed IP |
There are other examples in the main config file /etc/monit/monitrc
. This setup only allows access from my local subnet and as I used a fixed IP, I specify that IP.
I then access this from Node-Red (fill in your IP address) and output onto an MQTT broker as I explained in the past https://tech.borpin.co.uk/2017/03/21/node-red-and-xml-to-json/
by