[Linux] Using systemd to run a miner

As mining is a task meant to run continuously it is recommended to run orax-cli mine using a process manager/supervisor. We will see here how to use systemd for running your miner.

Download and register the miner

# Download the orax-cli binary
wget -O orax-cli https://oraxpool.s3.ca-central-1.amazonaws.com/orax-cli/orax-cli-linux-amd64
# Or the ARM version
# wget -O orax-cli https://oraxpool.s3.ca-central-1.amazonaws.com/orax-cli/orax-cli-linux-arm64
chmod +x orax-cli
sudo mv orax-cli /usr/local/bin/orax-cli
# Register your miner
orax-cli register

Set up systemd

Create a systemd unit file sudo nano /lib/systemd/system/orax.service with the following content while replacing the root user with your current user at the line User=root.

/lib/systemd/system/orax.service
[Unit]
Description=Orax miner
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/orax-cli mine
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target

Now load, enable and start Orax miner unit:

sudo systemctl daemon-reload
sudo systemctl enable orax
sudo systemctl start orax
sudo systemctl status orax

Read the logs

To read the logs, use journalctl:

journalctl -u orax.service --output cat
# To follow the logs:
journalctl -u orax.service --output cat -n 80 -f