Skip to content

Instantly share code, notes, and snippets.

@ForboleDevelopment
Last active September 30, 2020 07:10
Show Gist options
  • Save ForboleDevelopment/92979d9be88bd593f234e28ff2cd353a to your computer and use it in GitHub Desktop.
Save ForboleDevelopment/92979d9be88bd593f234e28ff2cd353a 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
USER=$(id -u -n)
# Setup GOBIN if not existent
if [ -z "$GOBIN" ]; then
echo "export GOBIN=$HOME/go/bin" >> ~/.profile
source ~/.profile
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
if [ -z "$DAEMON_NAME" ]; then
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
fi
######################
## 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.1
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=$USER
ExecStart=$GOBIN/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 <==="
@novy4
Copy link

novy4 commented Sep 16, 2020

[Service]
User=$(id -u -n)
ExecStart=/home/$(id -u -n)/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"

@ForboleDevelopment
Copy link
Author

Thank you very much @novy4! We've updated the script to include your suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment