I'm running Ubuntu 14.04. And I need to run xmr-stak-cpu as a service. I tried to search for a possible solution, but found only for systemctl, which is on Ubuntu 16. Is there a way/script to configure and run xmr-stak-cpu on Ubuntu 14.04 as a service?
2 Answers
Have you tried upstart
? See http://upstart.ubuntu.com/cookbook/
Also see: https://askubuntu.com/questions/351879/how-to-create-a-service-on-ubuntu-upstart/448536#448536
Upstart Example: /etc/init/xmrstakcpu.conf
# xmrstakcpu.conf
start on net-device-up IFACE=eth0
exec /usr/local/bin/xmr-stak-cpu/xmr-stak-cpu
This would run /usr/local/bin/xmr-stak-cpu/xmr-stak-cpu
after the Ethernet0
d device was initialized.
If you just want to run xmr-stak-cpu
in background - for instance after SSH - you can use
nohup ./xmr-stak-cpu &
This will run xmr-stak-cpu
and keep it active in background and log all output to a file nohup.out
, while you can logout
/ exit
SSH.
-
-
You can run programs under a different user using the
su
command. But I doubt this works for services. Commented Oct 30, 2017 at 3:52 -
-
Not sure. You can try it and after it runs you can use
ps
to see what user it is running on. Commented Oct 30, 2017 at 10:15
To create new upstart config
sudo nano /etc/init/xmrstakcpu.conf
Example of upstart configuration:
description "xmr-stak-cpu"
start on filesystem and net-device-up IFACE!=lo
script
echo $$ > /var/run/xmr.pid
exec su -s /bin/bash -c "nice -n19 /path/xmr-stak-cpu/bin/xmr-stak-cpu /path/xmr-stak-cpu/bin/config.txt" user_under_which_xmr_will_start
end script
pre-start script
echo "[`date`] Starting" >> /var/log/xmr.log
end script
pre-stop script
rm /var/run/xrm.pid
echo "[`date`] Stopping" >> /var/log/xmr.log
end script
Service usage:
sudo service xmrstakcpu start
sudo service xmrstakcpu stop