Setting up Cosmovisor

Automated Validator / Node Upgrades

About Cosmovisor

cosmovisor is a small process manager for Cosmos SDK application binaries that monitors the governance module for incoming chain upgrade proposals. If it sees a proposal that gets approved, cosmovisor it can automatically download the new binary, stop the current binary, switch from the old binary to the new one, and finally restart the node with the new binary.

Setup

Installation

You can download Cosmovisor from the GitHub releases.

  1. To install the latest version of cosmovisor, run the following command:

go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest
  1. Install from source

git clone git@github.com:cosmos/cosmos-sdk
cd cosmos-sdk
git checkout cosmovisor/vx.x.x
make cosmovisor

Run cosmovisor version to check the cosmovisor version.

Environment Variables

  • DAEMON_HOME is the location where upgrade binaries should be kept (e.g. $HOME/.selfchain).

  • DAEMON_NAME is the name of the binary itself (eg. selfchaind).

  • DAEMON_ALLOW_DOWNLOAD_BINARIES (optional) if set to true will enable the auto-downloading of new binaries (for security reasons, this is intended for full nodes rather than validators).

  • DAEMON_RESTART_AFTER_UPGRADE (optional) if set to true After a successful upgrade, it will restart the sub-process with the same command line arguments and flags (but a new binary).

Add the necessary environment variables, for example by adding these variables to the profile that will be running Cosmovisor. You can edit the ~/.profile file by adding the following content:

export DAEMON_NAME=selfchaind
export DAEMON_HOME="${HOME}"/.selfchain
export DAEMON_RESTART_AFTER_UPGRADE=true

The Data Folder Layout

$DAEMON_HOME/cosmovisor is expected to belong completely to cosmovisor the subprocesses that are controlled by it. The folder content is organized as follows:

$DAEMON_HOME
├── cosmovisor
│    ├── current -> genesis or upgrades/<name>
│    ├── genesis
│    │   └── bin
│    │       └── $DAEMON_NAME
│    └── upgrades
│        └── <name>
│            ├── bin
│            │   └── $DAEMON_NAME
│            └── upgrade-info.json
└── ...

Set up Genesis Binary

Create genesis folders:

mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin

Find the location of selfchaind:

which selfchaind

Copy the selfchaind binary to the genesis/bin from the path returned from the above command. Let's assume the returned path is /usr/local/go/bin/selfchaind .

cp /usr/local/go/bin/selfchaind $DAEMON_HOME/cosmovisor/genesis/bin

Configure the host's init system

Configure cosmovisor as a system service for automatically starting.

If you're on Linux, you can do this by creating a service:

sudo vi /etc/systemd/system/cosmovisor.service

Change the contents of the below to match your setup - cosmovisor

[Unit]
Description=cosmovisor
After=network-online.target

[Service]
User=<your-user>
ExecStart=/home/<your-user>/go/bin/cosmovisor run start
Restart=always
RestartSec=3
LimitNOFILE=4096
Environment="DAEMON_NAME=selfchaind"
Environment="DAEMON_HOME=/home/<your-user>/.selfchain"
Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=false"
Environment="DAEMON_RESTART_AFTER_UPGRADE=true"

[Install]
WantedBy=multi-user.target

Start Cosmovisor

Enable the service and start it:

sudo -S systemctl daemon-reload
sudo -S systemctl enable cosmovisor
sudo systemctl start cosmovisor

Check it is running using:

sudo systemctl status cosmovisor
journalctl -u cosmovisor -f

Last updated