skip to Main Content

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

  1. I download a File from the monero website containing a cli client
  2. I add this file to the root of my website and inside there is the an sh file
  3. connecting to my website using ssh and running ./file.sh will let me run the program or even just navigating to path-to-file/file.sh using the hosting site terminal
  4. 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


  1. 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:

    while true {
      if (connection fails) {
        retry
      }
      else
      {
        ....
      }
    }
    

    Running in background: ./file.sh & or nohup 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.

    Login or Signup to reply.
  2. The easiest way to do this is to install screen:

    apt-get install screen
    

    Then run screen:

    % screen
    Screen version 4.00.03 (FAU) 23-Oct-06
    ...
                            [Press Space or Return to end.]
    

    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:

    [detached]
    

    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:

    @reboot /usr/local/do-once.sh
    

    do-once.sh contains:

    #!/bin/sh
    
    while [ true ] ; do
        path-to-file/file.sh
        sleep 1
    done
    

    The cron way doesn’t allow you to see what the file.sh is doing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search