Making Avalanche Node Unstoppable!

Selcuk
4 min readFeb 5, 2021

--

Learn how to run a node using raspberry pi 4 8GB by using avalanchego.service file and avax-restart.sh ensure that you meet minimum uptime requirements for validating on Avalanche

Raspberry pi 4 8GB is one of the easiest solutions for the Avalanche community who is running a validator node in the house

One of the most common problems you may face is generally electric cuts and Internet disconnections, and if your distance is far from your home, it could be painful to go home re-power, and restart the process.

Reaching your node from work could make your API calls easier to check whether your node is working fine or not. For API calls, you may use “Putty” at your work’s computer or cellphone application like “JUICESSH” which has a snippets option for a reasonable price…

For more information about API Calls please visit docs.avax.network

If one of your API calls is false like “bootstrap” your node probably killed because of an unexpected situation. To raise validator node uptime and health, let’s check these simple steps below;

  1. Check your router performance and if it is frequently disconnected and using the router for a long time, there may not be functioning properly. A new router causes fewer problems.
  2. Connecting your node by wireless may damage the node’s database. Instead, connect your PI to your router by ethernet port. Closing wireless by editing config.txt on your Linux system prevents switching IP addresses because there are 2 inner IP addresses for wireless and ethernet ports.
  3. Connect your Pi and Router to UPS that 2 of them consume less electricity and this gives you long time working hours without main lines.
  4. Use avalanchego as service file.

Let’s explain 2 and 4 more detail

Disable Wifi on Raspberry Pi

config.txt file may be located in a different folder in your Linux system and it is generally in the /boot folder. Ubuntu-mate 20.01 and the file is in the /boot/firmware folder.

sudo nano /boot/firmware/config.txt

let’s open the config file using nano editor above code using “Sudo” if you are using your system as USER…

paste 2 codes below… bt is Bluetooth and it is up to you to disable it if necessary.

dtoverlay=disable-wifi
dtoverlay=disable-bt

Save with “ctrl + O” then exit and reboot your system. Check your inner Ip by typing “hostname-I” that shows the IP address of pi and it will no longer appear 2 addresses.

Creating avalanchego.service file

sudo nano /etc/systemd/system/avalanchego.service

Let’s paste the codes below in the nano text editor. Change USER below to your specific username in the system and your avalanche version either download from binary or source and please use exact location of avalanche folder that runs avalanchego. Replace your public IP address below written as x.x.x.x

if you dont have static ip type --dynamic-public-ip=opendns

save ctrl+O and exit nano editor…

[Unit]
Description=AVAX node
Wants=network-online.target
After=network.target network-online.target
[Unit]
Description=AVAX node
Wants=network-online.target
After=network.target network-online.target
[Service]
User=USER
WorkingDirectory=/home/USER/avalanchego-vX.X.X
ExecStart=/home/USER/avalanchego-vX.X.X/avalanchego --public-ip=x.x.x.x
KillMode=process
KillSignal=SIGINT
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=avalanchego
Restart=always
RestartSec=0
# Hardening measures
####################
# Provide a private /tmp and /var/tmp.
PrivateTmp=true
# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full
# Deny access to /home, /root and /run/user
# ProtectHome=true
# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true
# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true
[Install]
WantedBy=multi-user.target

To run the avalanchego.service lets type below;

sudo chmod 644 /etc/systemd/system/avalanchego.service
sudo systemctl start avalanchego
sudo systemctl enable avalanchego

to check the service whether working type ;

“ps aux | grep avalanchego” or

“systemctl status avalanchego” you may also see process

to check the system and restart, let’s create a shell file as avax-restart.sh and ask cron to check every 5 minutes and if avalanchego.service and if it was not working, Cron will attempt to restart our service file…

type “cd” and create again using nano editor;

sudo nano avax-restart.sh

lets paste the codes inside the editor. Let’s save and exit like we did earlier…

#!/bin/bashproc=”avalanchego”for pl in $proc
do
pc=`pidof $pl | wc -l`
if [ $pc -lt 1 ]; then
#Not working
sudo systemctl start avalanchego
#service avalanchego restart
fi
done

Now lets open Cron ;

crontab -e

let’s write this code without comment# the bottom of the page(be careful there are gap between star*. Change USER to your actual username;

*/5 * * * * USER /home/USER/avax-restart.sh

let’s save and exit again.

to activate “cron” type the below code…

chmod +x /home/USER/avax-restart.sh 
chown USER /home/USER/avax-restart.sh

Don’t forget to check your validator node by API calls and you may see the status of services we created below given codes;

systemctl status avalanchego
systemctl status cron

Special Thanks: Mr. Emre NOP [AMST] in telegram and Mrs. Burcusan helped me creating these codes and my validator node now %99 and never disconnected… We will mention later how to update node without stopping any service…

https://avascan.info/staking/validator/NodeID-62XYpHtuv92hHhJJXVd4wxJqPFv9rbWA8 you mat delegate you Avax to my Node.

--

--

Responses (1)