Firstly, I would like to reiterate the importance of chosing a high quality reliable VPS provider. Running the server daemon off of a home computer, or any computer / network that is not 99.9% stable presents problems. We highly discourage you from running the server daemon on an unreliable computer – If your home computer turns off, disconnects, reboots, etc, most likely your XRN will be locked for the remainder of your staking period. (< 30 days) If you are reading this and have the server daemon on a home pc, stop right now. Go purchase a reliable VPS or have our partner https://MNDown.com handle it for you.

 

Quick Notes before starting.

My VPS is running: Linux 4.16.14-feral x86_64

Use terminal command pwd to determine direct path.

Use terminal command ps x to show running procs, to kill a process type command kill and then it’s process ID kill 33333.

Use terminal keyboard shortcut CTRL + X to save nano files, or other information.

PS; Through this guide I will be replacing certain pieces of information for security purposes, typically my username for my server.

 

What needs to happen.

 

Here’s what needs to happen in order for this automated process:

1:) You must create a script to run screen + saronited —service-node 2:) You must create a “job” to run to check to see if “saronited” is running. “saronited” is the identifier we are going to attach to the “screen” and it will be an automated process which will run the server daemon; AKA “saronited –service-node” AKA the important part of your server 🙂

In this example, I am using the VPS provider FeralHosting.com – some variables may be different according to your vps host. I have had 100% uptime with FeralHosting, just saying.

 

PART 1 – SCRIPT CREATION

Firstly, log into your VPS and type ls this will print your current (typically home) directory. The name of the script we’re going to create is “saroscript” (our script we’re going to make for our automated cron job) in the base directory (( AKA ~/ (short key to get to your base dir is cd ~/ ))

Once in a directory where you can create files, lets say your home directory, type nano saroscript.sh (You may be prompted to select a text editor, I use Nano)

Once inside your new “saroscript.sh” get ready to paste the text below. BUT FIRST, you need to correct the location to the full path. This information can be obtained by typing  from the terminal command pwd . My example is on Pastebin at the link below, you will have to adjust it accordingly.

 

Saroscript Code is here: https://pastebin.com/TDmukUPr

#!/usr/bin/env bash

set -eux -o pipefail

[[ $(pgrep -fu $(whoami) ‘saronited’) ]] || screen -dmS saronited — /media/md1/YOURUSERNAME/saronite-linux-64-v1.1.1.0/saronited –service-node

You will need to change this bit: /media/md1/YOURUSERNAME/saronite-linux-64-v1.1.1.0/saronited --service-node

Change your directory, username and Saronite version respectively.

 Once you have updated line 3 to your relative directory location hold CTRL + X – then hit “y”, then enter to save your nano document.

After saving your new script, run this command in the directory where you created the script:  chmod 700 ~/saroscript.sh

This script is basically first a check (which is indicated by [[     ]] – It’s say “Check if “saronited” is running, if not then run the next line : screen -dmS saronited -- /media/md1/YOURUSERNAMEHERE/saronite-linux-64-v1.1.1.0/saronited --service-node

The script above firstly runs “screen” (as you learned from the node setup guide, screen creates a detached screen that will run in the background.) The script then gives the “screen” a name of “saronited” and then it calls this path /media/md1/YOURUSERNAMEHERE/saronite-linux-64-v1.1.1.0/saronited –service-node     (which if everything works, should turn on your service node)

 

Before moving forward, I would test this script by simply typing ./saroscript.sh in the directory it’s located.  For our example the dir it will run out of it is  your home dir ~/ “/media/md1/YOURHOMEDIRECTORY”  – – – Assuming your service node daemon (saronited –service-node) it not already running, it should start in a detached screen. Great!

If it’s already running, you will get something like:

 

+++ whoami

++ pgrep -fu YOURUSERNAME saronite

+ [[ -n 38333 ]]

Which means the script found “saronited” (or a similar process) already running as process ID 38333.
(optional) To list all detached screens type “screen -ls”.

To switch to  an already running “screen” type screen -x 38333(<- this would be your PID number, not necessarily 38333.

 

If you want to kill a screen process, type ps x then “kill yourprocessid here”.

 

PART 2 – CRONJOB CREATION

OKAY! Now you have created the script, and you know how to move between screens and understand the context of the situation lets move to creating the cronjob.

To open Crontab, in any area in linux, type crontab -e


You should be presented with a window with some marked out content indicated by ### symbols. Ignore these.
Arrow down to an area with no # symbols.
Get ready to copy and paste this, but before you do, you need to adjust it accordingly.

 

Pastebin here: https://pastebin.com/7hM7beBP

*/15 * * * * /media/md1/YOURUSERNAME/saroscript.sh >/media/md1/YOURUSERNAME/saroscript.sh.cronoutput 2>&1

Remember what we did earlier? Correcting the direct path? We have to do that again. Remember, command PWD gives you the full path of your current terminal location. Also recall that I created my “saroscript.sh” in my home directory of  “media/md1/YOURUSERNAME”

Once everything is correct, hold CTRL + X then hit “y”, enter to save your cronjob.

The above cronjob runs our “saroscript.sh” every 15 minutes. If the script detects that a process or screen is already running with the name “saronited” you will get a message like so:

 

+++ whoami

++ pgrep -fu YOURUSERNAME saronite

+ [[ -n 38333 ]]

The script we created also creates logs to output it’s most recent “job” – This information can be handy to see what happened on the last cronjob.

If you would like to see the most recent log output of your cronjob, simply browse to the location your created your “saroscript” probably in your home dir cd ~/ type ls and you’ll see “saroscript.sh.cronoutput” – type command nano saroscript.sh.cronoutput to see log.

If the server reboots, or loses power, the cronjob will automatically start within 15 minutes of the server booting up, it will check if screen / process “saronited” is running, when it detects it isn’t it will create a new screen and run the script “saroscript.sh” which will then run this command /media/md1/YOURUSERNAMEHERE/saronite-linux-64-v1.1.1.0/saronited --service-node which will start your service node 🙂

 

PART 3 – UPDATING CRONJOB / SCRIPT

So you’ve updated your Saronite Service node, but in that process you had to stop your cronjob in order to update.

Here’s what we need to fix in order to update the cronjob as well.

 

We need to correct the “saroscript.sh” we created.

Navigate to your home directory (cd ~/) and type “ls” – you should see “saroscript.sh”

Type: nano saroscript.sh

Once nano opens you will see something like this:

Using our same example as written above in PART 1:

#!/usr/bin/env bash

set -eux -o pipefail

[[ $(pgrep -fu $(whoami) ‘saronited’) ]] || screen -dmS saronited — /media/md1/YOURUSERNAME/saronite-linux-64-v1.1.1.0/saronited –service-node

We need to update the directory to point to the new version of the server daemon  you installed. So lets say you installed

“saronite-linux64-v1.2.0.0/”

You would need to update your “saroscript” to something like this:

#!/usr/bin/env bash

set -eux -o pipefail

[[ $(pgrep -fu $(whoami) ‘saronited’) ]] || screen -dmS saronited — /media/md1/YOURUSERNAME/saronite-linux64-v1.2.0.0/saronited –service-node

 

 Notice the bold bit 🙂 – CTRL + X then press Y then press enter. This will save the updated saroscript, which if done correctly, should run “saronite-linux64-v1.2.0.0/saronited –service-node”.

 

 

Hopefully that was pretty clear and hopefully this guide prevents your service node from being kicked off the network.

If you have questions or spotted an error in this guide feel free to ping mFridge_ on Discord.