Systemd Timer and monit

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)

and the monit.timer file looks like this

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;

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/

Facebooktwitterby feather
This entry was posted in Linux, Technical - General. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

*