Setup Cosmovisor
For mainnet, it’s recommended to use Cosmovisor to run your node.
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
Section titled “Install”First, go and get cosmovisor (recommended approach):
# to target a specific version:go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0Add environment variables to your shell
Section titled “Add environment variables to your shell”Some environment variables must be set to appropriate values for each node and each network.
echo "export DAEMON_NAME=sunrised" >> ~/.profileecho "export DAEMON_HOME=$HOME/.sunrised" >> ~/.profileecho "export DAEMON_ALLOW_DOWNLOAD_BINARIES=true" >> ~/.profileecho "export DAEMON_LOG_BUFFER_SIZE=512" >> ~/.profileecho "export DAEMON_RESTART_AFTER_UPGRADE=true" >> ~/.profileecho "export UNSAFE_SKIP_BACKUP=true" >> ~/.profileThen source your profile to have access to these variables:
source ~/.bash_profileSet up folder structure
Section titled “Set up folder structure”mkdir -p $DAEMON_HOME/cosmovisormkdir -p $DAEMON_HOME/cosmovisor/genesismkdir -p $DAEMON_HOME/cosmovisor/genesis/binmkdir -p $DAEMON_HOME/cosmovisor/upgradesSet up genesis binary
Section titled “Set up genesis binary”Cosmovisor needs to know which binary to use at genesis. We put this in $DAEMON_HOME/cosmovisor/genesis/bin
Check our Github to know the binary version of genesis.
wget https://github.com/sunriselayer/sunrise/releases/download/<version>/sunrisedcp sunrised $DAEMON_HOME/cosmovisor/genesis/binSet up service
Section titled “Set up service”Commands sent to Cosmovisor are sent to the underlying binary. For example, cosmovisor version is the same as typing sunrised version. Nevertheless, just as we would manage sunrised 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 vi /lib/systemd/system/cosmovisor.serviceChange the contents of the below to match your setup
[Unit]Description=Cosmovisor daemonAfter=network-online.target[Service]Environment="DAEMON_NAME=sunrised"Environment="DAEMON_HOME=$DAEMON_HOME"Environment="DAEMON_RESTART_AFTER_UPGRADE=true"Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=true" // RecommendEnvironment="DAEMON_LOG_BUFFER_SIZE=512"Environment="UNSAFE_SKIP_BACKUP=true"User=$USERExecStart=${HOME}/go/bin/cosmovisor startRestart=alwaysRestartSec=3LimitNOFILE=infinityLimitNPROC=infinity[Install]WantedBy=multi-user.targetStart Cosmovisor
Section titled “Start Cosmovisor”sudo systemctl daemon-reloadsudo systemctl restart systemd-journaldsudo systemctl enable cosmovisorsudo systemctl start cosmovisorCheck it is running using:
sudo systemctl status cosmovisorIf you need to monitor the service after launch, you can view the logs using:
sudo journalctl -u cosmovisor -f -o cat