---
# System prepended metadata

title: Cosmovisor setup for `bitcanna-1`
tags: [bitcanna, cosmovisor]

---

# Cosmovisor setup for `bitcanna-1`
`Cosmovisor` is a small process manager for Cosmos SDK application binaries that monitors the governance module for incoming chain upgrade proposals. If it sees a proposal that gets approved, it stops the current binary, switch from the old binary to the new one, and finally restarts the node with the new binary.

This guide will explain how to install Cosmovisor and prepare for a future chain update. A full guide about Cosmovisor can be found [here](https://github.com/cosmos/cosmos-sdk/tree/main/tools/cosmovisor).


## Step 1. Install/update Cosmovisor
You can build Cosmovisor from the source or download it from the official GitHub repository. 

The easy way is install with Go: 

`go install cosmossdk.io/tools/cosmovisor/cmd/cosmovisor@v1.4.0`


## Step 2. Setup Cosmovisor
> Version v1.2 and higher includes a new command that will create the required folder structure for you, so it will avoid you some extra steps

1) Download & init the folders with the old genesis version BitCanna `v1.2`  binary.
```
cd ~
rm -f bcnad #delete the binary if exist to avoid version mixings 
wget https://github.com/BitCannaGlobal/bcna/releases/download/v1.2/bcnad
chmod +x ./bcnad
#Set the necessaries VARs to start Cosmovisor (later you can add to .profile)
export DAEMON_NAME=bcnad
export DAEMON_RESTART_AFTER_UPGRADE=true
export DAEMON_HOME=${HOME}/.bcna
export DAEMON_RESTART_DELAY=30s
export UNSAFE_SKIP_BACKUP=true
export DAEMON_LOG_BUFFER_SIZE=512

#add this to continue to use bcnad for commands, this is optional
PATH="${HOME}/.bcna/cosmovisor/current/bin:$PATH" 

#start the initial configuration
cosmovisor init ./bcnad
```
It should show something like:
```
11:46AM INF checking on the genesis/bin directory module=cosmovisor
11:46AM INF creating directory (and any parents): "/Users/test/.bcna/cosmovisor/genesis/bin" module=cosmovisor
11:46AM INF checking on the genesis/bin executable module=cosmovisor
11:46AM INF copying executable into place: "/Users/test/.bcna/cosmovisor/genesis/bin/bcnad" module=cosmovisor
11:46AM INF making sure "/Users/test/.bcna/cosmovisor/genesis/bin/bcnad" is executable module=cosmovisor
11:46AM INF checking on the current symlink and creating it if needed module=cosmovisor
11:46AM INF the current symlink points to: "/Users/t/.bcna/cosmovisor/genesis/bin/bcnad" module=cosmovisor
```

2) Create new directory for next upgrades
```
mkdir -p ${HOME}/.bcna/cosmovisor/upgrades/ruderalis/bin
mkdir -p ${HOME}/.bcna/cosmovisor/upgrades/strangebuddheads/bin/
mkdir -p ${HOME}/.bcna/cosmovisor/upgrades/trichomemonster-ica/bin/
```

3a) Download & copy the next version `v.1.3.1` to the upgrades folder.
This guide shows how to download the binary. If you want to build the binary from the source, detailed instructions can be found in the [README](https://github.com/BitCannaGlobal/bcna/blob/main/README.md) of our GitHub.

```
cd ~
rm -f bcnad
wget -nc https://github.com/BitCannaGlobal/bcna/releases/download/v.1.3.1/bcnad
```
Check the sha256sum.
```
sha256sum ./bcnad
```
It must return: `ad6784e945135454efc436d22a7661db36bc6a396e7d9cdb7572c4d8d5ccef3f`

Verify that the version is:`.1.3.1`
```
chmod +x bcnad
./bcnad version
```
Move the newly built binary to the upgrades directory.
```
mv ./bcnad ${HOME}/.bcna/cosmovisor/upgrades/ruderalis/bin/
```
> If you build the binary from the code source move it to the same folder

3b) Download & copy the last version `v.1.4.5` to the upgrades folder.
This guide shows how to download the binary. If you want to build the binary from the source, detailed instructions can be found in the [README](https://github.com/BitCannaGlobal/bcna/blob/main/README.md) of our GitHub.

```
cd ~
rm bcna_linux_amd64.tar.gz #delete old file if exist
wget -nc https://github.com/BitCannaGlobal/bcna/releases/download/v1.4.5/bcna_linux_amd64.tar.gz
```
Check the sha256sum.
```
sha256sum bcna_linux_amd64.tar.gz
```
It must return: `a4ade068a9c3face2f6e5e052bcdd4d5f2fae52c0c9d6bb804dca565c5642180`

Extract and verify that the version is:`1.4.5`
```
rm -f ./bcnad #delete old file if exist
tar zxvf  bcna_linux_amd64.tar.gz
rm bcna_linux_amd64.tar.gz
chmod +x bcnad
./bcnad version
```
Move the newly built binary to the upgrades directory.
```
mv ./bcnad ${HOME}/.bcna/cosmovisor/upgrades/strangebuddheads/bin/
```

3c) **Download & copy the last version `v.1.5.3` to the upgrades folder**.
This guide shows how to download the binary. If you want to build the binary from the source, detailed instructions can be found in the [README](https://github.com/BitCannaGlobal/bcna/blob/main/README.md) of our GitHub.

```
cd ~
rm bcna_linux_amd64.tar.gz #delete old file if exist
wget -nc https://github.com/BitCannaGlobal/bcna/releases/download/v1.5.3/bcna_linux_amd64.tar.gz
```
Check the sha256sum.
```
sha256sum bcna_linux_amd64.tar.gz
```
It must return: `--------------------tda--------------------`

Extract and verify that the version is:`1.5.3`
```
rm -f ./bcnad #delete old file if exist
tar zxvf  bcna_linux_amd64.tar.gz
rm bcna_linux_amd64.tar.gz
chmod +x bcnad
./bcnad version
```
Move the newly built binary to the upgrades directory.
```
mv ./bcnad ${HOME}/.bcna/cosmovisor/upgrades/trichomemonster-ica/bin/
```


> If you build the binary from the code source move it to the same folder

4) Setup the current version link for Cosmovisor.
> Very important decision now. Depending on your choice you should sync the chain using a snapshot file/service or sync from the scratch (very slow process but the only to get the whole original chain by yourself)
* If you want to sync from the scratch (from block 1) you should do:
    ```
    ln -sfn -T ${HOME}/.bcna/cosmovisor/genesis ${HOME}/.bcna/cosmovisor/current
    ```
* If you are going to sync using **(advanced users)** a snapshot file, StateSync or other you should point to the last version (v1.4.5)
    ```
    ln -sfn  ${HOME}/.bcna/cosmovisor/upgrades/strangebuddheads ${HOME}/.bcna/cosmovisor/current
    ```
5) To check if everything is OK, run:
```
ls .bcna/cosmovisor/ -lh
```
The output should look like this:
```
total 8.0K
lrwxrwxrwx 1 user user   35 Jan 14 20:16 current -> /home/user/.bcna/cosmovisor/upgrades/strangebuddheads
drwxrwxr-x 3 user user 4.0K Jan 14 20:09 genesis
drwxrwxr-x 4 user user 4.0K Jan 14 20:15 upgrades
```


6. If you are a new user, you should  **Initialize the folders:** change **_Moniker_** by your validator name (use quotes for two or more separated words *"Royal Queen Seeds"*)
```
bcnad init Moniker --chain-id bitcanna-1 --overwrite
```
    This will create a `$HOME/.bcna` folder
7. Download the Genesis `genesis.json` file
```
cd $HOME
curl -s https://raw.githubusercontent.com/BitCannaGlobal/bcna/main/genesis.json > ~/.bcna/config/genesis.json
```
   Ensure you have the correct file. Run the SHA256SUM test:
```
 sha256sum $HOME/.bcna/config/genesis.json
 <output> cd7449a199e71c400778f894abb00874badda572ac5443b7ec48bb0aad052f29
```
8. Add to _config.toml_ file: server SEEDs:

```
sed -E -i 's/seeds = \".*\"/seeds = \"d6aa4c9f3ccecb0cc52109a95962b4618d69dd3f@seed1.bitcanna.io:26656,23671067d0fd40aec523290585c7d8e91034a771@seed2.bitcanna.io:26656\"/' $HOME/.bcna/config/config.toml
```
9. You can **set the minimum gas prices** for transactions to be accepted into your node’s mempool. This sets a lower bound on gas prices, preventing spam.
``` 
sed -E -i 's/minimum-gas-prices = \".*\"/minimum-gas-prices = \"0.001ubcna\"/' $HOME/.bcna/config/app.toml
```

10. Open the P2P port (26656 by default)
```
sudo ufw allow 26656
```
11) Create a systemd service for Cosmovisor. Simply copy and paste everything to create the service unit.
```
echo "[Unit]
Description=Cosmovisor BitCanna Service
After=network-online.target
[Service]
User=${USER}
Environment=DAEMON_NAME=bcnad
Environment=DAEMON_RESTART_AFTER_UPGRADE=true
Environment=DAEMON_HOME=${HOME}/.bcna
Environment=UNSAFE_SKIP_BACKUP=true #this will create (or skip) a backup before apply the new upgrade
Environment=DAEMON_RESTART_DELAY=30s #this means that will delay the start of the backup a bit
Environment=DAEMON_LOG_BUFFER_SIZE=512
#Optional export DAEMON_DATA_BACKUP_DIR=${HOME}/your_chain_backup_folder
ExecStart=$(which cosmovisor) run start
Restart=always
RestartSec=3
LimitNOFILE=4096
[Install]
WantedBy=multi-user.target
" >cosmovisor.service
```

12) Change **bcnad** service for `cosmovisor` service. You can avoid the 3rd line if it is a clean installation and `bcnad`service doesn't exist.
```
sudo mv cosmovisor.service /lib/systemd/system/
sudo systemctl daemon-reload
sudo systemctl stop bcnad.service && sudo systemctl disable bcnad.service 
sudo systemctl enable cosmovisor.service && sudo systemctl start cosmovisor.service
```

13) Check the logs to see if everything is OK. (ctrl + C to stop).
```
sudo journalctl -u cosmovisor -f -o cat
```
> You can speed up the syncing using a StateSync Server or a snapshot file.

## Step 3. Finish the installation
If everything is right Cosmovisor will take control of the binaries. Instead of **bcnad** you must use `cosmosvisor run` in your commands, for example: `cosmovisor run status`
To do this, make the following changes:

1) Add variables to the end of the **.profile** file.
```
nano $HOME/.profile
```
Add to the end of the file:
```
export DAEMON_NAME=bcnad
export DAEMON_RESTART_AFTER_UPGRADE=true
export DAEMON_HOME=${HOME}/.bcna
export UNSAFE_SKIP_BACKUP=true #if you want to skip automatic backup
export DAEMON_LOG_BUFFER_SIZE=512
export DAEMON_RESTART_DELAY=30s

#add this to continue to use bcnad for commands, this is optional
PATH="${HOME}/.bcna/cosmovisor/current/bin:$PATH" 
```

2) Reload the config of the **.profile** file.
```
source .profile
```
3) Now let's try Cosmovisor.

* Show Cosmovisor version: `cosmovisor run version`  Will be `v.1.4.5` before the upgrade and `v1.5.3` after the upgrade
```
 cosmovisor run version
 ```
 ```
12:14PM INF running app args=["version"] module=cosmovisor path=/home/testnet/.bcna/cosmovisor/genesis/bin/bcnad
12:14PM ERR failed to read error="lstat /home/testnet/.bcna/cosmovisor/current/upgrade-info.json: no such file or directory" filename=/home/testnet/.bcna/cosmovisor/current/upgrade-info.json module=cosmovisor
1.2
```
* Show BitCanna version: `bcnad version` Must show the same version as above
* Show Cosmovisor sync info and status: `cosmovisor run status` 


## Reminder
In the future, you must use the `cosmovisor` command instead of the **bcnad** command if you want to perform service related commands.

For example: 

* Start the service: `sudo service cosmovisor start`
* Stop the service: `sudo service cosmovisor stop`
* Restart the service: `sudo service cosmovisor restart`
* Check the logs: `sudo journalctl -u cosmovisor -f`




###### tags: `cosmovisor`, `bitcanna`