Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save novy4/8546a9caf3b4ca13ef14a69cedcbf130 to your computer and use it in GitHub Desktop.
Save novy4/8546a9caf3b4ca13ef14a69cedcbf130 to your computer and use it in GitHub Desktop.
This script allows you to setup Cosmovisor inside your Desmos node so that it will be able to automatically upgrade itself for the Desmos September Upgrade
#!/usr/bin/env bash
# This script allows the easy installation of the Cosmovisor daemon to watch
# any upgrade of your Desmos node.
# In order to run it properly, just execute this script giving it the path
# to the folder where you cloned Desmos.
# Example:
# ./install-cosmovisor.sh ~/desmos
DESMOS_PATH=$1
if [ -z "$DESMOS_PATH" ]; then
echo "Invalid Desmos code path. Please provide it as the first argument"
exit
fi
############################
## 1. Install cosmovisor ##
############################
echo "===> Installing cosmovisor <==="
mkdir -p ~/cosmos
cd ~/cosmos
git clone https://github.com/cosmos/cosmos-sdk.git .
cd cosmovisor
make cosmovisor
cp cosmovisor $GOBIN/cosmovisor
#########################
## 2. Setup cosmovisor ##
#########################
echo "===> Setting up cosmovisor <==="
mkdir -p ~/.desmosd/cosmovisor
mkdir -p ~/.desmosd/cosmovisor/genesis/bin
mkdir -p ~/.desmosd/cosmovisor/upgrades
cp $GOBIN/desmosd ~/.desmosd/cosmovisor/genesis/bin
echo " " >> ~/.profile
echo "# Setup Cosmovisor" >> ~/.profile
echo "export DAEMON_NAME=desmosd" >> ~/.profile
echo "export DAEMON_HOME=$HOME/.desmosd" >> ~/.profile
echo "export DAEMON_RESTART_AFTER_UPGRADE=on" >> ~/.profile
source ~/.profile
######################
## 2. Setup upgrade ##
######################
echo "===> Setting up september upgrade <==="
mkdir -p ~/.desmosd/cosmovisor/upgrades/september-upgrade/bin
cd $DESMOS_PATH
git fetch -a && git checkout tags/v0.12.0
make build
cp build/desmosd ~/.desmosd/cosmovisor/upgrades/september-upgrade/bin
######################
## 3. Setup service ##
######################
FILE=/etc/systemd/system/desmosd.service
if test -f "$FILE"; then
sudo tee $FILE > /dev/null <<EOF
[Unit]
Description=Desmosd Full Node
After=network-online.target
[Service]
User=ubuntu
ExecStart=/home/ubuntu/go/bin/cosmovisor start
Restart=always
RestartSec=3
LimitNOFILE=4096
Environment="DAEMON_NAME=desmosd"
Environment="DAEMON_HOME=$HOME/.desmosd"
Environment="DAEMON_RESTART_AFTER_UPGRADE=ony"
[Install]
WantedBy=multi-user.target
EOF
echo "===> Restarting service <==="
sudo systemctl stop desmosd
sudo systemctl daemon-reload
sudo systemctl start desmosd
fi
echo "===> Completed setup <==="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment