TUTORIAL | Auto-update and Auto-start scripts for mining rigs running on Linux
So you have configured your Linux mining rig and it works flawlessly, but you do not want to check on it every day or maybe you are going on vacation and you have to leave your lovely mining rig at home for two weeks... alone... :O How to make sure that everything is going to work even without your support? It's unbelievably easy and straight forward - you just gotta write two simple scritps called auto_start.sh
and auto_update.sh
Step 0:
First things first, before you start doing ANYTHING with your Linux system - always run:
sudo apt-get update && sudo apt-get upgrade -y
It's essential to keep your machine up to date before installing/configuring any new stuff.
Step 1:
Install tmux (that's a special thing for running multiple terminal windows/sessions and to be able to send keys keys in particular terminal window - it's gonna come in handy for our scripts):
sudo apt-get install tmux
Step 2:
Now things are gonna get a lil bit more complicated - you are going to write those two scripts... :O
Let's start with our
auto_start.sh
script first - open terminal, make sure, that you are in your home
folder (looks like this in terminal: ~) and type:
sudo nano auto_start.sh
Next an empty window of a terminal text editor should pop up. In that window type the following script:
#!/bin/bash
tmux new-session -d -n MINER
tmux send-keys -t MINER "cd /your/path/to/miner/folder" C-m
tmux send-keys -t MINER "sudo ./name_of_your_miner.sh" C-m
tmux send-keys -t MINER "your_password" C-m
*Where "your/path/to/miner/folder" represents the path to your miner folder, "your_password" your system password and "name_of_your_miner.sh" the name of the your miner's running script (obviously...). If you have other miner than EWBF"s CUDA or you are mining on AMD cards the starting script might have a different name so double check that! And btw. - you can name your session as you want - I named mine: MINER
It should look like this:
When you're done press ctrl + O
then enter
and then ctrl + X
to save and exit the text editor.
The second script is auto_update.sh
- in you terminal type:
sudo nano auto_update.sh
You will be welcomed by the same terminal text editor as the last time. This time type this script:
#!/bin/bash
tmux new-session -t updater
tmux send-keys -t updater "sudo apt autoremove --purge -y" C-m
tmux send-keys -t updater "your_password" C-m
tmux send-keys -t updater "sudo apt-get update && sudo apt-get upgrade -y" C-m
tmux send-keys -t updater "tmux kill-window" C-m
*Again - where "your_password" should be YOUR password :D and the session does not have to be called "updater" it can be called "nexus of the wisdom" if you would like to.
It should like this:
Again: ctrl + O
, enter
and ctrl + X
to save and exit the text editor.
If you open your home
folder you should find there your two scritps:
Step 3:
In order to run and test them type in your terminal:
sudo chmod +x auto_start.sh && sudo chmod +x auto_update.sh
then: ./auto_start.sh
to run your. Nothing should happen - in order to see the mining process, you have to open the special tmux window that we've created in our script. Type: tmux attach
(either in the same terminal or in new terminal window). If you have followed all the steps and typed everything right, you should see a terminal window pop up with your miner running:
To terminate the mininig process in your system open a separate terminal window and type:
tmux kill-window -t MINER
this gives tmux a command to terminate the particular tmux window called "MINER" (or whatever your one is gonna be called like):
Step 4:
To make these scripts run automatically on system boot, you gotta put them into the crontab
. To do that type crontabe -e
in your terminal window. You will be welcomed by a window full of text describing what crontab does and how to use it. Scroll to the bottom and there type:
@reboot /path/to/your/auto_start_script
@reboot /path/to/your/auto_update_script
*I really do not have to explain what does that code after "@reboot" do, do I? :)
Then traditionally hit ctrl + O
, enter
and ctrl + X
to save and exit the text editor. If there are no errors in your crontab command you should see the terminal writing that the new crontab is being installed:
And that's it - you are done! I strongly recommend you to turn off your password on log in and also turn off sleep mode in settings menu so that the system does not encounter any problems to run automatically by itself. To test the whole thing out reboot your system. Then open your terminal window and type: tmux attach
if you see the miner running you've done everything right and now can care much less about your miner, because from now on it's fully automated! :)
Please let me know in the comments below if everything went well, if you have any questions do not hesitate to ask - I would love to answer them. Upvote, resteem and follow me for more tutorials!
Also check out my other tutorial on how to set up and configure mining rig running on Linux: https://steemit.com/cryptocurrency/@lifipp/tutorial-or-how-to-set-up-and-configure-your-mining-rig-on-linux-nvidia-cards
Thank you for sharing this
You are always welcome @jraysteem :)
I've followed your easy to understand guide and now my Linux rigs are mining. Thank you so much! :)
Thank you for the excellent guide. This worked great for me. I did need to add the path to cudartlib in the environment file instead of where I had it just in the shrc file, but most people probably already had that set up properly. Another tip is to use "control-b" then "d" to detach from the tmux viewer. I find it nice to ssh into the system and use tmux attach to view the miner activity, then just detach and exit so I don't kill the session and have to start it over.
nice tutorial keep sharing thanks for this upvoted
Glad to help you @rudel :) thanks for upvoting!
I am not know about that... but good share... @lifipp
Thank you @heriafriadiaka :)
Very nice tutorial!
Just need some adjustments to run @ Ubuntu/Mint:
sudo crontab -e (You need to use the cron of root to be able to use @reboot)
The correct syntax of the command should be:
@reboot sleep 30; /path/to/your/auto_start_script
The "sleep 30" is needed to give enough time to let the OS mount the device where is the user script.
Very useful, helped a ton is an understatement. Tremendous!
This is amazing and I have now installed this on every rig, including my XMR CPU builds. However, on my 8-10 card GPU rigs I notice that there needs to be about a 10-30 second delay... otherwise only 5-7 of the cards fire up. Seems like there is a little "delay" that needs to be added. any ideas on this? something to make it so the SH miner script is delayed by 30 seconds? I've tested this several times and it does not effect the 6 card rigs the same way it effects the 8-10 card rigs. About 50% of the time they need a delay, otherwise every card does not fire up. any ideas for a "timeout" script?