Key and Account Confusion when Running gaiad as a Service
Scenario - Some of us run gaiad as a systemd service, using a specified user and gaiad home directory. Here’s an outdated script that creates the user and directory. It also starts gaiad using the specified home directory. The script is outdated, however the steps are the same for any testnet. gist.github.com https://gist.github.com/kwunyeung/bfc3a6c9f8e5ad2566f12e69419c64e6 gaia_install.sh ``` #!/bin/bash # Upgrade the system and install go sudo apt update sudo apt upgrade -y sudo apt install gcc git make -y sudo snap install --classic go sudo mkdir -p /opt/go/bin # Export environment variables ``` This file has been truncated. show original (Script written by @kwunyeung ) I’ve experienced confusion when declaring validator candidacy using this configuration. The confusion comes from having two different config directories - ~/.gaiad/config/ (This is the gaiad home directory of the user you’re logged-in as.) /opt/gaiad/config/ (This is the gaiad home directory of the user the script runs gaiad as.) I’m leaving the explanation in raw format. My hope is to come back to edit it. For now, I solved my issue by - -stopping gaiad…
Excerpt (1198 of 3501 characters). Read the whole post on the forum ↗
The `gaiad` is a node on the blockchain My script actually does the followings: • Update system software • Install Go • Setup correct paths for compiling • Create a new user `gaiad` without shell and set the home directory to `/opt/gaiad` • Get the cosmos repo and build the `gaiad` and `gaiacli` binaries • Copy the binaries to `/opt/go/bin` as system-wise • Install a systemd unit file which runs `gaiad` as a service as the user `gaiad` • Run `gaiad unsafe_reset_all` to create the `config` directory with `config.toml` and `priv_validator.json` As the home directory of the user `gaiad` is located at `/opt/gaiad`, I made the last command run as user `gaiad` and set the flag `--home=/opt/gaiad`. ``` sudo -u gaiad /opt/go/bin/gaiad unsafe_reset_all --home=/opt/gaiad ``` By doing this, the `config.toml` and `priv_validator.json` will be created at `/opt/gaiad/` correctly and accessible by the user `gaiad`. If you read the unit file `/etc/systemd/system/gaiad.service`, the `gaiad start` will run with flag `--home=/opt/gaiad` as user `gaiad`. `gaiad` will then start and read the config and write data to `/opt/gaiad/`. That’s why you also need to put the `genesis.json`…
Excerpt (1198 of 4369 characters). Read the whole post on the forum ↗
Great writeup @kwunyeung! Thank you!
kwunyeung: The `gaiad` is a node on the blockchain My script actually does the followings: • Update system software • Install Go • Setup correct paths for compiling • Create a new user `gaiad` without shell and set the home directory to `/opt/gaiad` • Get the cosmos repo and build the `gaiad` and `gaiacli` binaries • Copy the binaries to `/opt/go/bin` as system-wise • Install a systemd unit file which runs `gaiad` as a service as the user `gaiad` • Run `gaiad unsafe_reset_all` to create the `config` directory with `config.toml` and `priv_validator.json` As the home directory of the user `gaiad` is located at `/opt/gaiad` , I made the last command run as user `gaiad` and set the flag `--home=/opt/gaiad` . ``` sudo -u gaiad /opt/go/bin/gaiad unsafe_reset_all --home=/opt/gaiad ``` By doing this, the `config.toml` and `priv_validator.json` will be created at `/opt/gaiad/` correctly and accessible by the user `gaiad` . If you read the unit file `/etc/systemd/system/gaiad.service` , the `gaiad start` will run with flag `--home=/opt/gaiad` as user `gaiad` . `gaiad` will then start and read the config and write data to `/opt/gaiad/` . That’s why you also need to…
Excerpt (1196 of 4587 characters). Read the whole post on the forum ↗
gaiacli can talk to a remote node. Just add --node flag. You can also add this directly to the config by running
gaiacli config node <remote_node_address>
Then every time you run gaiacli, it will always communicate with this remote node. Again, the gaiacli is an interface to interact with the chain. It works as long as it talks to a node.