1

I haven't found any such command among the listed in the output of xmrig -h. I run the miner with "background": true in config.json.

As my xmrig is started in the background by a script that makes sure that my miner runs all the time in the background I need to know a command that gracefully exits the miner, under certain conditions included in the script. If there is such a command I would then add it to my script so that my miner can be stopped automatically. Because of the above reasons managing xmrig via tmux does not solve the problem, at least I can't see a way in which I can script starting and stopping xmrig with tmux.

2
  • 1
    pkill xmrig ?? (-9 to be nasty about it, if pkill supports -9) There was a small program ttyecho which can pipe/send commands into a tty. Would have to run ttyecho as root/sudo
    – Dave
    Jul 21, 2021 at 15:35
  • Scripting tmux is easy. Start xmrig in a named window, and kill-window the named window to kill it.
    – jtgrassie
    Jul 21, 2021 at 22:51

1 Answer 1

4

I've created a systemd unit file for xmrig: Command line options

nano /etc/systemd/system/xmrig.service

[Unit]
Description=XMRig Daemon
After=network.target
    
[Service]
User=user
Group=user
Type=simple
ExecStart=/home/user/xmrig/xmrig --config=/home/user/xmrig/config.json
Restart=always
    
[Install]
WantedBy=multi-user.target

Update systemd configuration and enable xmrig for system startup:

systemctl daemon-reload
systemctl enable xmrig.service

start, stop, status as usual:

systemctl start xmrig.service
systemctl status xmrig.service
systemctl stop xmrig.service
2
  • 1
    You should remove --background (because you've used Type=simple), and remove StandardOutput=null, StandardError=null, so you can read the output/log messages with journalctl. Lastly, on most systemd distros, you should create your custom service files under /etc/systemd/... not /usr/lib/systemd/; they will be correctly linked when enabled.
    – jtgrassie
    Jul 22, 2021 at 14:51
  • Adding a point to boldsuck's excellent service file answer. (Would add as a comment but don't have the rep on this group yet!) If you're running SELinux in enforcing mode (good for you!), these commands will allow xmrig to run as a service: sudo semanage fcontext -a "/home/USER/xmrig/xmrig" -t bin_t restorecon -rv /home/USER/xmrig Must have the policycoreutils-python-utils package Oct 24, 2021 at 1:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.