This guide will walk you through migrating from using 0gchaind start [flags] to using Cosmovisor to manage your 0gchaind application. Cosmovisor offers the advantage of handling upgrades automatically without manual intervention.
Stop node
sudo systemctl stop 0gd.service
Download cosmovisor script to install
wget https://raw.githubusercontent.com/0glabs/0g-chain/dev/networks/testnet/init-cosmovisor.sh
Note
Script:
echo " Usage: $0 <0G Home> "
go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@latest
export DAEMON_NAME = 0gchaind
echo " export DAEMON_NAME=0gchaind " >> ~/.profile
echo " export DAEMON_HOME= $1 " >> ~/.profile
cosmovisor init $( whereis -b 0gchaind | awk ' {print $2} ' )
mkdir $DAEMON_HOME /cosmovisor/backup
echo " export DAEMON_DATA_BACKUP_DIR= $DAEMON_HOME /cosmovisor/backup " >> ~/.profile
echo " export DAEMON_ALLOW_DOWNLOAD_BINARIES=true " >> ~/.profile
Run script
Before running this script, make sure Go is loaded in your current shell session.
If you haven’t loaded Go yet, please run the following command:
source $HOME /.bash_profile
#requirement go version above v.1.22
chmod +x init-cosmovisor.sh
./init-cosmovisor.sh /root/.0gchain
Edit service file to run with Cosmovisor
sudo tee /etc/systemd/system/0gd.service > /dev/null << EOF
Description=Cosmovisor 0G Node
ExecStart=/root/go/bin/cosmovisor run start --log_output_console
Environment="DAEMON_NAME=0gchaind"
Environment="DAEMON_HOME=/root/.0gchain"
Environment="DAEMON_ALLOW_DOWNLOAD_BINARIES=true"
Environment="DAEMON_RESTART_AFTER_UPGRADE=true"
Environment="DAEMON_DATA_BACKUP_DIR=/root/.0gchain/cosmovisor/backup"
Environment="UNSAFE_SKIP_BACKUP=true"
WantedBy=multi-user.target
Reload daemon and restart node
sudo systemctl daemon-reload && \
sudo systemctl enable 0gd && \
sudo systemctl restart 0gd && sudo systemctl status 0gd && \
sudo journalctl -u 0gd -f -o cat
tail -f /root/.0gchain/log/chain.log