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.

Install

First, go and get cosmovisor (recommended approach):
1
go get github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor
2
3
# or, with go >= 1.15 you can do
4
go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/[email protected]
5
6
# to target a specific version:
7
go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/[email protected]
Copied!
Note that the latest version of Cosmovisor (v1.0.0 as of 2021-09-30) has not been used in a Juno testnet. It contains important security fixes but is likely not compatible with using Cosmovisor'sDAEMON_ALLOW_DOWNLOAD_BINARIESoption. In any case, the Juno team do not recommend running with auto downloads turned on, so this should not be an issue.
To build a specific version, you can use the instructions below, or use the previous release tag for Cosmovisor here.
Once this has been deployed in production and tested, the Juno team will update this warning message.
Your installation can be confirmed with:
1
which cosmovisor
Copied!
This will return something like:
1
/home/<your-user>/go/bin/cosmovisor
Copied!
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-sdk repo on Github, so you can use Git tags to target a specific version. This example uses a tag, v0.42.7 that 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, cosmovisor/v1.0.0.
1
git clone https://github.com/cosmos/cosmos-sdk
2
cd cosmos-sdk
3
git checkout v0.42.7
4
make cosmovisor
5
cp cosmovisor/cosmovisor $GOPATH/bin/cosmovisor
6
cd $HOME
Copied!

Add environment variables to your shell

In the .profile file, usually located at ~/.profile, add:
1
export DAEMON_NAME=junod
2
export DAEMON_HOME=$HOME/.juno
Copied!
Then source your profile to have access to these variables:
1
source ~/.profile
Copied!
You can confirm success like so:
1
echo $DAEMON_NAME
Copied!
It should return junod.

Set up folder structure

Cosmovisor expects a certain folder structure:
1
.
2
├── current -> genesis or upgrades/<name>
3
├── genesis
4
│ └── bin
5
│ └── $DAEMON_NAME
6
└── upgrades
7
└── <name>
8
└── bin
9
└── $DAEMON_NAME
Copied!
Don't worry about current - that is simply a symlink used by Cosmovisor. The other folders will need setting up, but this is easy:
1
mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin
2
mkdir -p $DAEMON_HOME/cosmovisor/upgrades
Copied!

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 the binary you want to use:
1
which junod
Copied!
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/junod:
1
cp /home/<your-user>/go/bin/junod $DAEMON_HOME/cosmovisor/genesis/bin
Copied!
Once you're done, check the folder structure looks correct using a tool like tree.

Set up service

Commands sent to Cosmovisor are sent to the underlying binary. For example, cosmovisor version is the same as typing junod version.
Nevertheless, just as we would manage junod using 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:
1
sudo nano /etc/systemd/system/cosmovisor.service
Copied!
Change the contents of the below to match your setup - cosmovisor is likely at ~/go/bin/cosmovisor regardless of which installation path you took above, but it's worth checking.
1
[Unit]
2
Description=cosmovisor
3
After=network-online.target
4
5
[Service]
6
User=<your-user>
7
ExecStart=/home/<your-user>/go/bin/cosmovisor start
8
Restart=always
9
RestartSec=3
10
LimitNOFILE=4096
11
Environment="DAEMON_NAME=junod"
12
Environment="DAEMON_HOME=/home/<your-user>/.juno"
13
Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=false"
14
Environment="DAEMON_RESTART_AFTER_UPGRADE=true"
15
Environment="DAEMON_LOG_BUFFER_SIZE=512"
16
17
[Install]
18
WantedBy=multi-user.target
Copied!
A description of what the environment variables do can be found here. Change them depending on your setup.
Note also that we set buffer size explicitly because of a live bug in Cosmovisor before version v1.0.0. If you are using v1.0.0, you may omit that line.
In addition, the same issue can be fixed by reducing the log via env variable. If you are unsure, ask on Discord.

Start Cosmovisor

Finally, enable the service and start it.
1
sudo -S systemctl daemon-reload
2
sudo -S systemctl enable cosmovisor
3
sudo systemctl start cosmovisor
Copied!
Check it is running using:
1
sudo systemctl status cosmovisor
Copied!
If you need to monitor the service after launch, you can view the logs using:
1
journalctl -u cosmovisor -f
Copied!
Last modified 10d ago