Writing a systemd service for AVA testnet on Ubuntu

Dogus Ural
2 min readMay 2, 2020

--

Long waited Avalanche test-net has arrived. There is nothing better than tinkering with the system to have deep understanding.

If you follow the instructions on the official ava hub you will have a working node in less than than 10 minutes. But running it once only solves half of the problems. To have a stable network for the developers & testers there must be as much online nodes as possible. Network failures, reboots, crashes may happen and so there must be an automated way to make our process recover from any possible fail scenario.

This is where Linux services come into play, they are easy to write and deploy. The service that we are going to write tries to bring our process back to life as long as our OS is running.

If you did everything right, you should have an executable called ava under

/src/github.com/ava-labs/gecko/build

We will start with creating our service file under /etc/systemd/system

sudo touch /etc/systemd/system/ava.service

Open the file with your favourite text editor with sudo and add the following lines :

[Unit]
Description=AVA test node
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
WorkingDirectory=<gecko_folder>
Restart=always
RestartSec=1
User=<your_user_name>
ExecStart=<your_ava_build_folder>
[Install]
WantedBy=multi-user.target

Replace the User and ExecStart fields with your values.

To give an example: build folder and gecko folder on my Ubuntu Server machine is :

ExecStart=/home/dodo/workspace/src/github.com/ava-labs/gecko/build/ava
WorkingDirectory=/home/dodo/workspace/src/github.com/ava-labs/gecko
  • RestartSec=1 , means the service will try to bring the process back alive every second when it is down.
  • StartLimitIntervalSec=0, makes sure service will try forever to make the process work. Normally if the process fails more than 5 times in 10 seconds. Service stops bothering.
  • WorkingDirectory , ava executable is expecting certificates and RSA keys to be under …/src/github.com/ava-labs/gecko/keys folder, relative to the gecko folder. When we are calling the ava executable with the absolute path, the keys folder name cant be resolved. So we set our process’s cwd to gecko folder. (I looked for a command line argument that may solve this to no avail)

Run this commands to start automating your ava test node.

systemctl start avasystemctl enable ava

If all is well , run the code below and you should see the ava service active running in the terminal

systemctl | grep ava.service

Make sure your node is online with

ps aux | grep ava

That is all folks, happy testing .

--

--