Cosmovisor Guide

Cosmovisor is a comprehensive process manager that can serve as an easy substitute for the standard initiad start command. It is designed for both manual use and as a system service, offering automatic updates for blockchains based on the Cosmos SDK.

Cosmovisor's main role is to keep track of software upgrade proposal signals and automatically download and update the node to the new binary following proposal approval.

Set up Cosmovisor

To set up Cosmovisor, you may follow different steps depending on your specific environment. There are two main paths:

  1. Install initiad Locally: This involves installing initiad directly onto your local machine.

  2. Using a Prebuilt Binary of the initiad Program: This involves using a prebuilt binary of the initiad Program. This can be particularly useful if you want to avoid the hassle of building initiad from source.

Please ensure to follow the correct instructions for your specific environment to avoid any issues during setup.

Install initiad Locally

1. Set up Cosmovisor

go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest

export DAEMON_HOME=~/.initia
export DAEMON_NAME=initiad


cosmovisor init ~/go/bin/initiad # <path-to-executable>

# only if there is planned upgrade
export UPGRADE_NAME=<upgrade-name>
export UPGRADE_VERSION=<upgrade-version>
mkdir -p $DAEMON_HOME/cosmovisor/upgrades/$UPGRADE_NAME/bin
(                                                                              \
	cd initia &&                                                           \
	git fetch --all --tags &&                                              \
	git checkout $UPGRADE_VERSION &&                                       \
	make build &&                                                          \
	mv ./build/initiad $DAEMON_HOME/cosmovisor/upgrades/$UPGRADE_NAME/bin/ \
)

2. Update System Service File

[Unit]
Description=initiad

[Service]
Type=simple
User=ubuntu
ExecStart=/home/ubuntu/go/bin/cosmovisor run start --home /home/ubuntu/.initia
WorkingDirectory=/home/ubuntu/.initia
Restart=on-abort
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=initiad
LimitNOFILE=4096
Environment="DAEMON_NAME=initiad"
Environment="DAEMON_HOME=/home/ubuntu/.initia" 
Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=false"
Environment="DAEMON_RESTART_AFTER_UPGRADE=true"

[Install]
WantedBy=multi-user.target

3. Restart initiad

sudo systemctl daemon-reload
sudo systemctl restart initiad

Using a Prebuilt Binary of initiad

1. Set up Cosmovisor

go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest

export DAEMON_HOME=~/.initia
export DAEMON_NAME=initiad

cosmovisor init `<path-to-executable>`
cp `<shared-library-path>` $DAEMON_HOME/current/bin/

# only if there is planned upgrade
export UPGRADE_NAME=<upgrade-name>
export UPGRADE_VERSION=<upgrade-version>
mkdir -p $DAEMON_HOME/cosmovisor/upgrades/$UPGRADE_NAME/bin
cd $DAEMON_HOME/cosmovisor/upgrades/$UPGRADE_NAME/bin
wget https://initia.s3.ap-southeast-1.amazonaws.com/mahalo-1/initia_$UPGRADE_VERSION_$(uname)_$(uname -m).tar.gz
tar -xzvf initia_$UPGRADE_VERSION_$(uname)_$(uname -m).tar.gz
rm initia_$UPGRADE_VERSION_$(uname)_$(uname -m).tar.gz

2. Update System Service File

[Unit]
Description=initiad

[Service]
Type=simple
User=ubuntu
ExecStart=/home/ubuntu/go/bin/cosmovisor run start --home /home/ubuntu/.initia
WorkingDirectory=/home/ubuntu/.initia
Restart=on-abort
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=initiad
LimitNOFILE=4096
Environment="DAEMON_NAME=initiad"
Environment="DAEMON_HOME=/home/ubuntu/.initia" 
Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=false"
Environment="DAEMON_RESTART_AFTER_UPGRADE=true"
Environment="LD_LIBRARY_PATH=/home/ubuntu/.initia/cosmovisor/current/bin"

[Install]
WantedBy=multi-user.target

3. Restart initiad

sudo systemctl daemon-reload
sudo systemctl stop initiad 
rm `<shared-library-path>` # to prevent loading wrong shared library
sudo systemctl start initiad

Last updated