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):
go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest
To install a previous version, you can specify the version after the @ sign. Note that versions older than 1.4.0 can also target a specific version, at a slightly different location:
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. Ensure you have the environment variable DAEMON_ALLOW_DOWNLOAD_BINARIES set to false.
Your installation can be confirmed with:
which cosmovisorThis will return something like:
/home/<your-user>/go/bin/cosmovisorYou 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.
git clone https://github.com/cosmos/cosmos-sdk
cd cosmos-sdk
git checkout v0.42.7
make cosmovisor
cp cosmovisor/cosmovisor $GOPATH/bin/cosmovisor
cd $HOMEAdd environment variables to your shell
In the .profile file, usually located at ~/.profile, add:
export DAEMON_NAME=junod
export DAEMON_HOME=$HOME/.junoThen source your profile to have access to these variables:
source ~/.profileYou can confirm success like so:
echo $DAEMON_NAMEIt should return junod.
Set up folder structure
Cosmovisor expects a certain folder structure:
.
├── current -> genesis or upgrades/<name>
├── genesis
│ └── bin
│ └── $DAEMON_NAME
└── upgrades
└── <name>
└── bin
└── $DAEMON_NAMEDon'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/upgradesSet 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:
which junodThen 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:
cp $HOME/go/bin/junod $DAEMON_HOME/cosmovisor/genesis/bincp $HOME/go/bin/junod $DAEMON_HOME/cosmovisor/genesis/binCosmovisor init
Post v1 versions of Cosmovisor have a command that will create the directories and copy the junod binary into the proper directory. To create the directories and copy the binary, run this command:
cosmovisor init $HOME/go/bin/junodOnce 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:
sudo nano /etc/systemd/system/junod.serviceChange 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.
Note cosmovisor run start is only for the latest versions of cosmovisor. For earlier versions that line should be:
ExecStart=/home/<your-user>/go/bin/cosmovisor start[Unit]
Description=Juno Daemon (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=junod"
Environment="DAEMON_HOME=/home/<your-user>/.juno"
Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=false"
Environment="DAEMON_RESTART_AFTER_UPGRADE=true"
Environment="DAEMON_LOG_BUFFER_SIZE=512"
[Install]
WantedBy=multi-user.targetNote 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
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 junod
# check config one last time before starting!
sudo systemctl start junodCheck it is running using:
sudo systemctl status junodIf you need to monitor the service after launch, you can view the logs using:
journalctl -fu junodLast updated
Was this helpful?
