monit - interfejs web

Domoticz part 8 – Stable instance of Domoticz, 24/7/365 mode – high availability at home

As a result, a both fresh and advanced user finds himself in a situation where the system – ceases to work at all, or requires frequent restarts, or worse causes quick degradation of the main storage device – which is often (micro) SD card.

Is there a simple and effective solution to increase Domoticz’s availability on Raspberry Pi / Orange Pi?

Sure there is! But first – before you begin – make a copy of your (micro)SD working used in domoticz instance on your Raspberry Pi/Orange Pi.
CAUTION: We will perform operations that may lead to the loss of all data – so make sure you have a copy!

What will you need?

Software:

  • monit
  • rsync

Hardware:

  • harddrive either classic HDD or better SSD, small is OK from 32GB up to 128GB
  • heatsinks for Raspberry Pi/Orange Pi
  • USB 2.0 or 3.0 to SATA adapter – so we can connect the harddrive via USB port

Let’s do it!

The plan is very simple – connect the hard disk, move data and check if we have heat sinks. SSD type disk is recommended due to long life, reliability and low power consumption. Even the older designs are fine or MLC/TLC flash type based- will serve us for a very long time. We will transfer the following resources to the disk:

  • /root – this is one of the domoticz possible location
  • /home – old style installation folder for domoticz
  • /var – fast changing files, databases, possibly influxdb

While switching to a solid disk (SSD) – we cannot neglect the microSD card – avoid any no-name cards, and remember to verify the named ones by registering on the manufacturer’s website. The “endurance” cards can be also used, but usually their price is close to the price of the SSD.

The risk of the damage to the micro SD will be significantly reduced after the switch, especially the unfamous problem of the physical damage to the card’s cells when power cycling the computer

Don’t forget to put the heat sinks on the CPU, memory and controller – RPi 3 gets quite hot!

Hardware – the SSD

The SSD needs to have:

  • SATA interface
  • 5V only voltage
  • power (mA), the best if it reaches a 50% of the max. 800mA of the Raspberry Pi3’s USB port, enable max_current=1 for older models or Zero

You will need to purchase a USB-SATA adapter/bridge for 2.5″ SATA disks, to be able to connect a SSD with a SATA interface, with the integrated, USB-sourced power. Adapters with one USB 3.0 connector (blue), compatible with USB 2.0 and based on the JMicron chipset are recommended. I’m using today (3 years) an old one – without trim/ATA support.

Please test the connection of the disk to an already working Raspberry Pi, and during the restart – please note the behavior of the Pi’s red LED – it cannot go off, neither a lightning bolt icon might appear in the case you’re uning monitor via HDMI / CVSB.

Issue the “dmesg” command after connecting new SSD, output should be similar:

This gives us the following information: this is the only external drive, system knows it as /dev/sda, first partition is /dev/sda1. Next up is the task of formatting that partition (deletes all data!) with the ext4 file system (side note: B-tree File System or Butter FS is also good choice, but we talk stable here).

First – let’s install new software:

Then issue the mkfs command on your Pi (make sure it’s the right Pi, the right partition – as the process deletes all data).

Now, lets mount the new drive to check if it works:

The dmesg should show us:

Now update the /etc/fstab with the following from the top:

It’s time to turn off all services – except sshd – so we can tranfer all the files to SSD. It sould be done on other computer with system not working but the risk is rather low.

Copy the /home /root i /var to SSD.

Check:

This should give us a long list of files.
Now restart your Pi and after booting up – check:

Expected result:

Stable software – monit

Domoticz is quite a complex software, often incorporates code of different quality and development dynamics. As a result, adding even an innocent sensor or function – may cause destabilization – even if using official stable version. A good remedy for the “Domoticz offline” syndrome is monit – a piece of software that can be used to monitor domoticz’s operation (of course not only domoticz), restarting it after crash while having a nice web interface.

Since we installed monit in previous step – let’s edit the /etc/monit/monitrc – find this section and modify it – the PASSWORD and “httpd port” value

Then add the domoticz section (assuming it’s there using port 8080, and has no username/password for localhost):

Start monit:

Check the monit’s web interface – you should get similar results:

monit - interfejs web
monit – interfejs web

Some final thoughts on the first part: The best way is to have trim support – but most of the adapter/bridges doesn’t pass the ATA/trim command, which means that it’s good to do manual fstrim – at the time of regular micro SD card backup – by means of connecting the SSD to other computer.

Don’t forget this is not 100% proof solution, it’s a step to extend life and make the system more stable. The next part will add the ongoing and needed backup to external filesystem (NFS), and proper installation of external power (UPS).