Setting up Cosmovisor
For mainnet, it's recommended to use Cosmovisor to run your node. If you've not used it before, then run it during a testnet to check you can get it set up correctly.
Setting up Cosmovisor is relatively straightforward. However, it does expect certain environment variables and folder structure to be set.
Cosmovisor allows you to download binaries ahead of time for chain upgrades, meaning that you can do zero (or close to zero) downtime chain upgrades. It's also useful if your local timezone means that a chain upgrade will fall at a bad time.
Rather than having to do stressful ops tasks late at night, it's always better if you can automate them away, and that's what Cosmovisor tries to do.
First, go and get cosmovisor (recommended approach):
go get github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor
# or, with go >= 1.15 you can do
go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@latest
# to target a specific version:
go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/[email protected]
When using cosmovisor, make sure that you do not have auto download of binaries on.
Your installation can be confirmed with:
This will return something like:
Building from source allows you to target a specific version of Cosmovisor, in case you do not want to run 1.0.0 yet.
You can also build from source; cosmovisor is in the main
cosmos-sdkrepo on Github, so you can use Git tags to target a specific version. This example uses a tag,
v0.42.7that refers to the Cosmos SDK, as Cosmovisor-specific tags did not exist before August 2021. The first of these was
cosmovisor/v0.1.0, and the second is the current release,
git clone https://github.com/cosmos/cosmos-sdk
git checkout v0.42.7
cp cosmovisor/cosmovisor $GOPATH/bin/cosmovisor
.profilefile, usually located at
Then source your profile to have access to these variables:
You can confirm success like so:
It should return
Cosmovisor expects a certain folder structure:
├── current -> genesis or upgrades/<name>
│ └── bin
│ └── $DAEMON_NAME
Don't worry about
current- that is simply a symlink used by Cosmovisor. The other folders will need setting up, but this is easy:
mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin
mkdir -p $DAEMON_HOME/cosmovisor/upgrades
Cosmovisor needs to know which binary to use at genesis. We put this in
First, find the location of the binary you want to use:
Then use the path returned to copy it to the directory Cosmovisor expects. Let's assume the previous command returned
cp /home/<your-user>/go/bin/sourced $DAEMON_HOME/cosmovisor/genesis/bin
Once you're done, check the folder structure looks correct using a tool like
Commands sent to Cosmovisor are sent to the underlying binary. For example,
cosmovisor versionis the same as typing
Nevertheless, just as we would manage
sourcedusing a process manager, we would like to make sure Cosmovisor is automatically restarted if something happens, for example an error or reboot.
First, create the service file:
sudo nano /etc/systemd/system/cosmovisor.service
Change the contents of the below to match your setup -
cosmovisoris likely at
~/go/bin/cosmovisorregardless of which installation path you took above, but it's worth checking.
In addition, the same issue can be fixed by reducing the log via env variable. If you are unsure, ask on Discord.
If syncing from a snapshot, do not start Cosmovisor yet.
Finally, 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
If you need to monitor the service after launch, you can view the logs using:
journalctl -u cosmovisor -f