How to pass multiple parameters to systemd’s ExecStart – Running same ethminer instance with multiple GPUs with systemd

For our Ethereum mining rig a coworker of mine wrote a systemd template unit so it is relatively easy to configure which graphic card in the rig is assigned to whom.

For each of the GPU owners exist a custom configuration file /etc/sysconfig/ethminer-$USERNAME (/etc/sysconfig/ethminer-ckl in my case). The file contains the following parameters:

ETHER_ADDRESS=0xYOUR_HASH
EMAIL_ADDRESS=<your email address>
# use first three GPUs, last three would be 3 4 5
OPENCL_DEVICES=0 1 2

Each user has its own configuration file and all services can be started like

systemctl start ethminer@ckl

But when ethminer was started by using systemctl start only the first GPU in the defintion was used – GPU 0 in the configuration sample above. systemd itself called the ethminer binary in a correct way and the same command line worked when executed by hand. The problem occurred by how systemd passes arguments and how ethminer reads the them. In the end I fixed it by wrapping the ethminer command in a sub-bash process. Our unit definition in /etc/sysconfig/ethminer@.service looked like this:

[Unit]
Description=Mine Ether for %i
After=network.target


[Service]
User=nobody
EnvironmentFile=/etc/sysconfig/ethminer-%I
# BEFORE AND NOT WORKING
# ExecStart=/usr/bin/ethminer --farm-recheck 2000 -G -S eth-eu1.nanopool.org:9999 -O ${ETHER_ADDRESS}/rig02/${EMAIL_ADDRESS} --opencl-devices ${OPENCL_DEVICES}

ExecStart=/bin/bash --login -c "/usr/bin/ethminer --farm-recheck 2000 -G -S eth-eu1.nanopool.org:9999 -O ${ETHER_ADDRESS}/rig02/${EMAIL_ADDRESS} --opencl-devices ${OPENCL_DEVICES}"

Restart=always

[Install]
WantedBy=multi-user.target