Skip to main content

Setting up Cosmovisor

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 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โ€‹

  1. Install the latest version of cosmovisor
$ go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/[email protected]
  1. Install from source
$ git clone [email protected]:cosmos/cosmos-sdk
$ cd cosmos-sdk
$ git checkout cosmovisor/vx.x.x
$ make cosmovisor

This will build cosmovisor in /cosmovisor directory. Afterwards you may want to put it into your machine's PATH like as follows:

$ cp cosmovisor/cosmovisor ~/go/bin/cosmovisor

Add environment variables to your shellโ€‹

In the .profile file, usually located at ~/.profile, add:

export DAEMON_NAME=aurad
export DAEMON_HOME=$HOME/.aura
export DAEMON_RESTART_AFTER_UPGRADE=true

Then source your profile:

$ source ~/.profile

Set up folder structureโ€‹

Cosmovisor expects a certain folder structure:

$DAEMON_HOME
โ”œโ”€โ”€ cosmovisor
โ”‚ โ”œโ”€โ”€ current -> genesis or upgrades/<name>
โ”‚ โ”œโ”€โ”€ genesis
โ”‚ โ”‚ย ย  โ””โ”€โ”€ bin
โ”‚ โ”‚ย ย  โ””โ”€โ”€ $DAEMON_NAME
โ”‚ โ””โ”€โ”€ upgrades
โ”‚ โ””โ”€โ”€ <name>
โ”‚ โ”œโ”€โ”€ bin
โ”‚ โ”‚ย ย  โ””โ”€โ”€ $DAEMON_NAME
โ”‚ โ””โ”€โ”€ upgrade-info.json
โ””โ”€โ”€ ...

current - a symlink used by Cosmovisor. The other folders will need setting up:

$ mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin
$ mkdir -p $DAEMON_HOME/cosmovisor/upgrades

Set up genesis binaryโ€‹

Cosmovisor needs to know which binary to use at genesis. We put this in $DAEMON_HOME/cosmovisor/genesis/bin First, find the location of aurad:

which aurad

Then use the path returned to copy it to the directory Cosmovisor expects. Let's assume the previous command returned /home/<your-user>/go/bin/aurad

$ cp /home/<your-user>/go/bin/aurad $DAEMON_HOME/cosmovisor/genesis/bin

Configure the host's init systemโ€‹

Configure cosmovisor as a system serivce for automatically starting.

systemd is used for demonstration.

First, create the service file:

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 start
Restart=always
RestartSec=3
LimitNOFILE=4096
Environment="DAEMON_NAME=aurad"
Environment="DAEMON_HOME=/home/<your-user>/.aura"
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