Chia Blockchain

News site specializing in Chia and related technologies

Running hpool-miner as a service on Linux

troubleshooting computer software problems

Not sure what happened in the past few days but my hpool-miner stopped at least two or three times. I only caught it when I checked the hpool main website. Upon looking at the logs there was nothing so I decided it’s the time to create an hpool-miner service that would auto start and restart the service so I would not need to worry about these kind of things any longer. As always I will try to make it easy for anyone, not too familiar with Linux, in case you have any questions, feel free to ask.

Getting started

I use Rasbian 32 bit version, even though I have the 8 GB version. The reason to the 32 bit is because this is what the hpool dev team uses to test their code. As you may know a 32 bit Operating System cannot address larger than 4 GB memory space but that only applicable at the per processes level so I decided 32 bit is good for me. Rasbian is a variant of the Debian Linux distribution and it uses systemd that is a Linux initialization system and service manager. In case you do this thing the first time I highly recommend you not to mess up with your current config so copy instead of moving or deleting the configurations. I would like to avoid being blamed that you got stuck and you cannot farm :).

Creation of the hpool-miner service

  • Create the service file for hpool-miner

sudo vim /etc/systemd/system/hpool-miner@.service # I use vim to create/edit file, you can use something else

[Unit]
Description=HPool miner: %i
After=network.target
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
Restart=on-failure
RestartSec=5s
WorkingDirectory=/opt/hpool-miner
User=%i
Group=%i
ExecStart=/opt/hpool-miner/hpool-chia-miner-linux-arm -config /home/%i/cfg/config.yaml
LimitNOFILE=999999
[Install]
WantedBy=multi-user.target

Without getting into the details, the important part is that it will try to start hpool-miner 5 times in case of a failure, wait 500 sec between the retries and obviously it would start it when your system starts. Few things that requires changes from your end:

  • Create new user/group
  • Move hpool-miner binary
  • Create custom directory for the configuration

Let’s get into that part.

Further customization

  • Create a new user: You will have a new /home/hpool directroy and it will auto create hpool group too. This user does not need to have login access so you can exclude it from the sshd config file.

sudo adduser hpool

  • Deny the new hpool user’s SSH access

vim /etc/ssh/sshd_config

and add the following line to the bottom of the file

DenyUsers hpool

  • Restart SSH service

sudo systemctl restart ssh.service

  • Move the hpool binary under /opt/hpool-miner

mkdir /opt/hpool-miner

  • Copy the binary

cp /from/where/your/miner/currently/is/hpool-chia-miner-linux-arm /opt/hpool-miner/

  • Put the config file under the dedicated hpool user’s home directory

mkdir /home/hpool/cfg/

  • Move the config file

cp /from/where/your/config.yaml/currently/is/config.yaml /opt/hpool-miner/

Edit config.yaml and change the logging path

vim ./config.yaml
log:
lv: debug
path: /home/hpool/log
name: miner.log

I cheated here, I not only changed ‘path:’ but I also raised the logging level ‘lv’ to debug.

Add the systemd service and then start

sudo systemctl enable hpool-miner@hpool and then sudo service hpool-miner@hpool start

Verification

user@farmer:~ $ systemctl status hpool-miner@hpool.service
● hpool-miner@hpool.service - HPool miner: hpool
Loaded: loaded (/etc/systemd/system/hpool-miner@.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-06-16 07:06:48 CEST; 4h 24min ago
Main PID: 4030 (hpool-chia-mine)
Tasks: 20 (limit: 4915)
CGroup: /system.slice/system-hpool\x2dminer.slice/hpool-miner@hpool.service
└─4030 /opt/hpool-miner/hpool-chia-miner-linux-arm -config /home/hpool/cfg/config.yaml
Jun 16 11:31:01 farmer hpool-chia-miner-linux-arm[4030]: ...

Troubleshooting

Going forward hpool logs will be here (based on the config file you modified before): /home/hpool/log

  • Checking service status:

corvin@farmer:/home/hpool/cfg $ systemctl list-units --type=service | grep hpool
hpool-miner@hpool.service loaded active running HPool miner: hpool

and obviously

systemctl status hpool-miner@hpool.service

  • In case the startup failed you may need to clear the failed status, you can do with: sudo systemctl reset-failed
  • Usually follow with: sudo systemctl daemon-reload

If you need to disable the service then do sudo systemctl disable hpool-miner@hpool.

Hope it will work for you! BTW this is not only relevant for hpool, you can use it for anything else for example for the official chia software as well.