Hello, could you help me?
Is there any way to make cgminer start automatically by the ubuntu server? Via terminal.
When you turn on the computer, the system starts the cgminer.sh script automatically and opens cgminer on the screen?
Does anyone know how to do this?
Thank you so much.
Sure.
You can use
screen to start your script and keep it running in the background. So, for example, let's say your username in the computer is
BiticaMan, and your script to start the miner is in
/home/BiticaMan/start_cgminer.sh, you can run this:
screen -dm -S cgminer /home/BiticaMan/start_cgminer.sh
That will start the script and keep it running in the background. You can see it anytime by writing:
screen -r cgminer
To go back, simply
press Ctrl-a, and then Ctrl-d. If you don't understand this, it means press and hold Control key, then press the letter a. That puts you in the command mode. You want to Detach it, so the command you want is executed by holding Control key and then pressing the letter d. That's it.
Make sure this is running properly and that you can see the miner working properly at the cgminer screen and back.
Once that's running correctly, just put it inside a startup file, like
/etc/rc.local This service should be already available on raspberry pis, and older ubuntus. You can check if the service is available with this:
sudo systemctl status rc-local
If it's available, you can skip the next part. For newer ubuntus you'll have to enable it, like this:
Open this file:
sudo nano /etc/systemd/system/rc-local.service
Paste this into it:
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
Enable it:
sudo systemctl enable rc-local
Now reboot.
sudo reboot now
You can check that the service is now available:
sudo systemctl status rc-local
OK, let's use /etc/rc.local
sudo nano /etc/rc.local
This will open a text editor. Write the following at the end of the file:
su - BiticaMan -c "screen -dm -S cgminer /home/BiticaMan/start_cgminer.sh"
This does exactly the same as before, but the difference is that since it will be executed at startup by root, it tells it to run the script as your user instead.
If the file is empty, that's fine, just add this in the beginning:
#!/bin/bash
Press Ctrl-O to save, and then Ctrl-X to exit.
Also, make sure the file is executable:
sudo chmod a+x /etc/rc.local
And that's it. Your script will now be executed on restarts.
This should work for a Raspberry Pi, or Ubuntu, etc.