I have a WordPress site, my sitehave unlimited source to use. Which is why I decided to run monero CLI miner on it to make some monero. This is how the whole operation works
- I download a File from the monero website containing a cli client
- I add this file to the root of my website and inside there is the an
sh
file - connecting to my website using
ssh
and running./file.sh
will let me run the program or even just navigating topath-to-file/file.sh
using the hosting site terminal - by doing the above steps everything works perfectly
The problem:
whenever I do this the program works and it will start mining using the website source. But if for some reason I close the ssh connection
, the browser with the hosting terminal, or I lost connection locally the Monero Cli will stop.
Example: If I open my PC prompt and run ping google.com
and don’t close the prompt it will run for ever, but if I lost connection it will stop.
Solution:
I need to make a cron job that will make the Cli run from within the website itself but this job needs to run only once or even better have it run again in case the script stops, this way I dont have to keep checking in case the server goes down for whatever reason. I want to be able to tell the website to run the script locally all by itself, this way it wont depend on 3rd parties having to run it, because when you have to run it from the outside, as soon the internet connection is lost everything will stop.
if the script is run using a cron job, is like doing a ping google.com
that will run for ever.
2
Answers
You can add your logic within a infinite loop and add a reconnect logic whenever the connection fails. Then run this as a background process.
Example script:
Running in background:
./file.sh &
ornohup file.sh
The only disadvantage is that when the server restarts, you will have to re-run the script.
Alternative to running it in background is to create a systemd service that starts the script when the server starts up.
The easiest way to do this is to install screen:
Then run screen:
Once you have it running, use your program:
./file.sh
Then detach from the screen by doing Ctrl-A then pressing lowercase "d". You will see:
Log out of ssh. Log back in. Run
screen -R
and you will be back to your application.Alternatively you can do this in the background with cron:
do-once.sh contains:
The cron way doesn’t allow you to see what the file.sh is doing.