Chia Plot and Farming Setup with SystemD

Chia Plotting Hardware

There are many guides around regarding Chia hardware and performance. I followed some of them and ended up ordering the following configuration for my plotter
  • Intel NUC10i7FNH2
  • Kingston KCP426SD8/32 (1x, 32GB, DDR4-RAM, SO-DIMM 260 pin)
  • Kingston A400 (480GB, 2.5")
  • Corsair Force MP510
I'm quite happy with this build although I'm only able to plot around 14 plots per day - with no notifications to the hardware/no overclocking, etc. However, I would go with a bigger SSD than the 480GB. It has more then enough space for the OS and blockchain, but it's very tight when using it as destination in plotman before the plots are archived. Better go for a 1 TB drive there.

👉 Tipp: Go for a 1TB SSD, so you will have enough space for the OS, Blockchain, Logs and Destination folder for Plotman. I made the mistake and went for a 512GB, which turned out to be a bottleneck.

Software

I'm using the following software for my installation. Detailed configuration below

Since this is my first build, I wanted to understand all the different tools and their behavior. For multiple builds, there are more advanced monitoring solutions like Monitoring my Chia Farm (kmr.me)

The interesting bits: Configuration

Numerous reports suggest that at least the build-in plotter is around 10% faster on Linux than on Windows. In addition to that, there is bigger tooling support and command line support on Linux. So I went for Ubuntu 20.04 Desktop. Server would work as well, but you might want to have a graphical UI with VNC/TeamViewer just in case... 

Chia Installation

There is no much special here, I first though about having a separate user for chia, but turned out this makes everything more complex (different permissions, user groups, etc.). So I installed chia-blockchain in the user home directory, following the official guide: INSTALL · Chia-Network/chia-blockchain Wiki (github.com) 

👉 Tipp: Make sure you don't use sudo to install anything chia related, it will mess up your installation!

Depending on your home-partition, you might want to move the .chia-data folder to a different partition. I did that, and moved the whole .chia folder to my root partition under /var/local/chia.

mis@lx-nuc:~ $ sudo ln -s /var/local/chia /home/mis/.chia

Folder Structure

I'm using a top level folder /chia in the root partition where I mount all the devices, shares etc. I find this quiet convenient, having everything available under /chia (except chia, itself you might say...). 

mis@lx-nuc01:/chia$ tree -d . ├── dst │   ├── external │   └── internal ├── farm │   ├── nas-share01 │   ├── nas-share02 │   ├── usb-wd01 │   └── usb-wd02 └── tmp 9 directories

Where as

  • /dst: Is the destination folder where the chia plotter moves the plots as part of the last step and plotman picks them up to move them ton one of the farm buckets. I do have two dst-folders, one is on the root-filesystem (internal), where the other is a mounted external SSD drive (external)
  • /farm: Here I have all the mount-points for the storage drives/shares that hold my plots. This is also referred as archive location in plotman. The beauty of having all under the same folder, is the ability to pass the root folder /chia/farm to plotman, and plotman will distribute finished plots automatically
  • /tmp: This is my internal NVME drive, which is used as temporary directory when creating new plots

Mount Points

External devices and network shares are mount into the /chia folder structure. All the external devices are auto-mount on start with entries in /etc/fstab.

👉 Tipp: You really want to make sure your node will recover after a restart, so do not rely on the graphical UI to mount your USB devices on start. Tell it the system itself!

/dev/disk/by-uuid/... /chia/tmp auto discard,defaults,nosuid,nodev,nofail,x-gvfs-show 0 0 /dev/disk/by-id/... /chia/farm/usb-wd01 auto defaults,uid=1000,gid=1000,x-gvfs-show 0 0 /dev/disk/by-id/... /chia/farm/usb-wd02 auto defaults,uid=1000,gid=1000,x-gvfs-show 0 0 /dev/disk/by-id/...   /chia/dst/external auto defaults,uid=1000,gid=1000,x-gvfs-show 0 0 //192.168.0.1/chia01 /chia/farm/nas-share01 cifs username=YOU,password=hello,vers=2.0,uid=1000,gid=1000,forceuid,forcegid 0 0 //192.168.0.1/chia02 /chia/farm/nas-share02 cifs username=YOU,password=hello,vers=2.0,uid=1000,gid=1000,forceuid,forcegid 0 0


The configuration has two important parts, which took me a couple of hours to get it right

Permissions

The USB attached drives should be mount under the user that will access them to avoid any permission issues. In my case, this is the user mis, therefore I added the userId and groupId as parameters, so the permissions on the mountpoint are set correctly

Network Shares

The important bit here is the vers=2.0, which avoided compatibility issues with my NAS, and again the user information, together with forceuid and forcegid to override information from NAS.

Plotman


Plotman is installed into the virtual environment of chia-blockchain. Find your own configuration options for plotting. As a reference, here is and except of the relevant parts of my ~/.config/plotman/plotman.yaml

logging: plots: /var/log/chia/plotter commands: interactive: autostart_plotting: False autostart_archiving: False directories tmp: - chia/tmp dst: - chia/dst/internal - chia/dst/external archiving: target: local_rsync env: command: rsync site_root: /chia/farm scheduling tmpdir_stagger_phase_major: 2 tmpdir_stagger_phase_minor: 1 tmpdir_stagger_phase_limit: 4 tmpdir_max_jobs: 9 global_max_jobs: 20 global_stagger_m: 86

👉 Tipp: Plotman should run as service and not as interactive application. To avoid any unwanted behavior when running in interactive mode in the console, I disabled both autostart plotting and archiving as this is handled in the background!

Installing as service

Plotman is a great tool as bases entirely on logfiles and process information. This means, you can kill plotman process and the creation or archival of plots is not affected. If you start plotman again in interactive mode, or just get the status, it will always show the status based in processes and logfile content.

This makes plotman a perfect candidate to run as service, to it continues creating new plots in the background. Plotman has two main functionalities
  • Create new Plots in tpm-folder(s): plotman plot
    This command keeps starting creation of new plots if possible. Runs in a loop only stops when the process is killed
  • Archive plots from the dst-folder(s): plotman archive
    This command looks for finished plots and distributes them into the farm. Runs in a loop as well and never stops 

For plotman I created the following services

/etc/systemd/system/plotman-plotter.service

[Unit] Description=Plotman Plotting Service After=network.target StartLimitIntervalSec=0 [Service] Type=simple Restart=always RestartSec=1 User=mis ExecStart=/bin/sh -c ". /home/mis/chia-blockchain/activate && plotman plot" [Install] WantedBy=multi-user.target

/etc/systemd/system/plotman-archive.service

[Unit] Description=Plotman Archiver Service After=network.target StartLimitIntervalSec=0 [Service] Type=simple Restart=always RestartSec=1 User=mis ExecStart=/bin/sh -c ". /home/mis/chia-blockchain/activate && plotman archive" [Install] WantedBy=multi-user.target

Both have to be activated so that they start when the system starts

mis@lx-nuc:~ $ sudo systemctl enable plotman-plotter.service
Created symlink

mis@lx-nuc:~ $ sudo systemctl enable plotman-archive.service
Created symlink ...

Controlling them is done using systemctl

mis@lx-nuc:~ $ sudo systemctl start plotman-plotter
mis@lx-nuc:~ $ sudo systemctl start plotman-archive

and to monitor the current console output of these services, I found journalctl quite useful, with the switch -f to follow the tail. See View stdout/stderr of systemd service – iTecTec for details.

mis@lx-nuc01:~$ sudo journalctl -u plotman-archive -f
-- Logs begin at Tue 2021-07-13 01:47:20 CEST. --
Jul 19 00:46:29 lx-nuc01 sh[2280047]: Sleeping 60s until next iteration...
Jul 19 00:46:29 lx-nuc01 sh[2280047]: Sleeping 60s until next iteration...
Jul 19 00:46:29 lx-nuc01 sh[2280047]: Sleeping 60s until next iteration...
Jul 19 00:46:29 lx-nuc01 sh[2280047]: Sleeping 60s until next iteration...
Jul 19 00:46:29 lx-nuc01 sh[2280047]: Sleeping 60s until next iteration...
Jul 19 00:46:29 lx-nuc01 sh[2280047]: Sleeping 60s until next iteration...
Jul 19 00:46:29 lx-nuc01 sh[2280047]: Sleeping 60s until next iteration...
Jul 19 00:46:29 lx-nuc01 sh[2280047]: Sleeping 60s until next iteration...
Jul 19 00:46:29 lx-nuc01 sh[2280047]: Sleeping 60s until next iteration...
Jul 19 00:46:29 lx-nuc01 sh[2280047]: Sleeping 60s until next iteration...


ChiaDog


Chia Dog pretty much bases on the default installation from martomi/chiadog: A watch dog providing a peace in mind that your Chia farm is running smoothly 24/7. (github.com). I'm using both Telegram and the keep alive monitor integration with Healthchecks.io. This pretty neat, as it will inform you on additional channels if your ChiaDog has not called a certain HealthChecks.io Url.

Installing as service

Luckily, ChiaDog already brings a shell-script to setup the python environment and start the application. The only thing we have to do, is to create a valid service. See below

/etc/systemd/system/chiadog.service

[Unit] Description=ChiaDog Monitoring Service After=network.target StartLimitIntervalSec=0
[Service]
Type=simple Restart=always RestartSec=1 User=mis WorkingDirectory=/home/mis/chiadog ExecStart=/bin/sh /home/mis/chiadog/start.sh [Install] WantedBy=multi-user.target


Again the service has to be activated and started using systemctl and service

mis@lx-nuc:~ $ sudo systemctl enable chiadog
mis@lx-nuc:~ $ sudo systemctl start chiadog

This service can also be monitored using journalctl -u chiadog -f

farmr.net


Last but not least I was looking for a simple dashboard accessible via web-browser in addition to the telegram bot. I found farmr.net to do exactly what I wanted.

Installing the farmr-client is as simple as downloading the latest deb package and install it

mis@lx-nuc01:~$ wget https://github.com/joaquimguimaraes/farmr/releases/download/v1.5.3.4/farmr-ubuntu-x86_64.deb
mis@lx-nuc:~ $ sudo dpkg -i farmr-ubuntu-x86_64.dev

According to the following GitHub issue (SystemD Support · Issue #34 · joaquimguimaraes/farmr (github.com)), there should be systemd support since a couple of days, however this did not work for me and I ended up creating a very similar unit file as show below

~/etc/systemd/system/farmr.service

[Unit] Description=farmr.net client service After=network.target StartLimitIntervalSec=0 [Service] Type=simple Restart=always RestartSec=1 User=mis ExecStart=/usr/bin/farmr headless [Install] WantedBy=multi-user.target

👉 Tipp: Note the additional headless parameter. It is required so that the application does not expect and input from and interactive session. As we are running it as deamon it would fail without.

Again the service has to be activate and started using systemctl and service

mis@lx-nuc:~ $ sudo systemctl enable farmr
mis@lx-nuc:~ $ sudo systemctl start farmr

This service can also be monitored using sudo journalctl -u farmr -f. A successful start should look similar as the one below:

Jul 19 05:06:57 lx-nuc01 systemd[1]: Started farmr.net client service. Jul 19 05:07:01 lx-nuc01 farmr[2415445]: ============================================ Jul 19 05:07:01 lx-nuc01 farmr[2415445]: Your id is XXXXXXXX-XXXX-XXXX-XXX-XXXXXXXXXXXX-xch, visit https://farmr.net to add it to your account. Jul 19 05:07:01 lx-nuc01 farmr[2415445]: Alternatively, you can also link it through farmrbot (a discord bot) by running the following command: Jul 19 05:07:01 lx-nuc01 farmr[2415445]: !chia link XXXXXXXX-XXXX-XXXX-XXX-XXXXXXXXXXXX-xch Jul 19 05:07:01 lx-nuc01 farmr[2415445]: to link this client to your discord user Jul 19 05:07:01 lx-nuc01 farmr[2415445]: You can interact with farmrbot in Swar's Chia Community Jul 19 05:07:01 lx-nuc01 farmr[2415445]: Open the following link to join the server: https://discord.gg/fghFbffYsC Jul 19 05:07:01 lx-nuc01 farmr[2415445]: =========================================== Jul 19 05:07:01 lx-nuc01 farmr[2415445]: Running in headless mode


Missing 'headless' Exception

Should you experience any errors on start, it has most likely to do with your configuration. How ever I run into an issue not having 'headless' as parameter on the service start. This will cause an error message in farmr similar to this

Select action: Unhandled exception: type 'Null' is not a subtype of type 'FutureOr<String>' #0 _AsyncCompleter.complete (dart:async/future_impl.dart:46) #1 Prompter.prompt.<anonymous closure>.<anonymous closure> (package:console/src/prompt.dart:222) #2 new Future.<anonymous closure> (dart:async/future.dart:174) #3 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18) #4 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:395) #5 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:426) #6 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184)

Fixing the below unhandled exception is a matter simply adding the parameter 'headless' to the executable

Comments

Popular posts from this blog

Use Bodmer TFT_eSPI Library with PlatformIO

Migrating from Arduino IDE to Visual Studio Code to PlatformIO