Create Service for miner on Arch

in #xmr4 years ago

A mining rig should work more self-contained. This means for example that the miner software is start automatically on start-up of the machine.
I will show how to create a service for XMRIG, which executed on start-up of the machine and restarting the service, if it crashes.

Systemd is used by Arch Linux and other distributions as unify system and service manager.
The file of the service will be placed in /lib/system/system/xmrig.service. Systemd uses a declarative language inspired by the XDG Desktop Entry Specification .desktop files, which is inspired by Microsoft Windows .ini-files.
A .service-file consists of three parts: Unit, Service and Install.

The Service

Unit section

In the Unit section, some general information is set for the service, i. g. a description. But there is much more and one of most commonly used settings is After. After is specifying the sequence of starting the services. For the miner it is important that the Network service is already running.

Service section

In this section, you configure what the service is running, by which privileges it runs, fail safe options and much more. I will concentrate on options for making the mining rig self-contained. The service will be restarted automatically if it is fails by the option Restart=always. I want my rig to restart automatically after to 2, RestartSec=2.
In the option ExecStart the path to the executable is set, /usr/sbin/xmrig -c /etc/xmrig/monero.json. In Addition to this option there some option you may consider like ExecReload, ExecCondition, ExecStartPre, ExecStartPost, ExecStop and ExecStopPost. If ExecStop is not specified, systemd will send SIGTERM to all processes of the service.

Install section

This area is used to specify, when the service is executed/started. The rig more less needs the whole system to started, there for I set it to multi-user.target (Runlevel 3).

Complete Service file

[Unit]
Description=XMRIG Monero Service
After=network.target
[Service]
Restart=always
RestartSec=2
ExecStart=/usr/sbin/xmrig -c /etc/xmrig/monero.json
User=root
[Install]
WantedBy=multi-user.target

Service Installation

After copy the service file into /lib/systemd/system, it is necessary to reload the systemds' daemon.
sudo systemctl daemon-reload
Now the newly avaliable service needs to be enabled for the system start-up and than started.
sudo systemctl enable xmrig
sudo systemctl start xmrig

Please up vote, comment and resteem my post. If you like this please donate to 42D2sPUubqCCqK3MD8BnDDSyjgNqbrLH6HcHXrZWaqYZfUqyoDcRsfTQNp345N1NSDLr8qBJ5QqjQ4V95nix6qH9Je8BX2U
Thank you so much in advance.

Coin Marketplace

STEEM 0.20
TRX 0.12
JST 0.029
BTC 60870.17
ETH 3385.85
USDT 1.00
SBD 2.57