Skip to content

Commit

Permalink
Fix START_CMD implementation (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
tombeynon authored Jul 12, 2023
1 parent 0cad4f0 commit f64daaa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ The node binary can be downloaded at runtime when using the [Generic image](#gen
|`PROJECT_BIN`|Binary name|`$PROJECT`|`osmosisd`|
|`PROJECT_DIR`|Name of project directory|`.$PROJECT_BIN`|`.osmosisd`|

### Cosmovisor

[Cosmovisor](https://docs.cosmos.network/main/tooling/cosmovisor) can be downloaded at runtime to automatically manage chain upgrades. You should be familiar with how Cosmovisor works before using this feature.

|Variable|Description|Default|Examples|
|---|---|---|---|
|`COSMOVISOR_ENABLED`|Enable Cosmovisor binary download and support| |`1`|
|`COSMOVISOR_VERSION`|Version of Cosmovisor to download|`1.3.0`| |
|`COSMOVISOR_URL`|Alternative full URL to Cosmovisor binary tar.gz| | |

### Shortcuts

See [Cosmos docs](https://docs.tendermint.com/master/nodes/configuration.html) for more information
Expand Down
32 changes: 19 additions & 13 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ fi
export PROJECT_BIN="${PROJECT_BIN:-$PROJECT}"
export PROJECT_DIR="${PROJECT_DIR:-.$PROJECT_BIN}"
export CONFIG_DIR="${CONFIG_DIR:-config}"
if [ "$COSMOVISOR_ENABLED" == "1" ]; then
PREFIX_CMD="cosmovisor run"
elif [ -n "$SNAPSHOT_PATH" ]; then
PREFIX_CMD="snapshot.sh"
else
PREFIX_CMD=
fi
export PROJECT_ROOT="/root/$PROJECT_DIR"
export CONFIG_PATH="${CONFIG_PATH:-$PROJECT_ROOT/$CONFIG_DIR}"
export NAMESPACE="${NAMESPACE:-$(echo ${PROJECT_BIN^^})}"
Expand Down Expand Up @@ -324,13 +317,14 @@ fi
# Cosmovisor
if [ "$COSMOVISOR_ENABLED" == "1" ]; then
export COSMOVISOR_VERSION="${COSMOVISOR_VERSION:-"1.3.0"}"
export COSMOVISOR_URL="${COSMOVISOR_URL:-"https://github.com/cosmos/cosmos-sdk/releases/download/cosmovisor%2Fv$COSMOVISOR_VERSION/cosmovisor-v$COSMOVISOR_VERSION-$(uname -s)-$(uname -m | sed "s|x86_64|amd64|").tar.gz"}"

# Download Binary
if [ ! -f "/bin/cosmovisor" ]; then
echo "Downloading the cosmovisor ($COSMOVISOR_VERSION) binary..."
echo "Downloading Cosmovisor from $COSMOVISOR_URL..."
mkdir -p cosmovisor_temp
cd cosmovisor_temp
curl -Ls "https://github.com/cosmos/cosmos-sdk/releases/download/cosmovisor%2Fv$COSMOVISOR_VERSION/cosmovisor-v$COSMOVISOR_VERSION-$(uname -s)-$(uname -m | sed "s|x86_64|amd64|").tar.gz" | tar zx
curl -Ls $COSMOVISOR_URL | tar zx
cp cosmovisor /bin/cosmovisor
cd ..
rm -r cosmovisor_temp
Expand All @@ -354,9 +348,21 @@ if [[ ! -f "$PROJECT_ROOT/data/priv_validator_state.json" ]]; then
fi

if [ "$#" -ne 0 ]; then
exec $PREFIX_CMD "$@"
elif [ -n "$START_CMD" ]; then
exec $PREFIX_CMD $START_CMD
export START_CMD="$@"
fi

if [ -z "$START_CMD" ]; then
if [ "$COSMOVISOR_ENABLED" == "1" ]; then
export START_CMD="cosmovisor run start"
else
export START_CMD="$PROJECT_BIN start"
fi
fi

if [ -n "$SNAPSHOT_PATH" ]; then
echo "Running '$START_CMD' with snapshot..."
exec snapshot.sh "$START_CMD"
else
exec $PREFIX_CMD $PROJECT_BIN start
echo "Running '$START_CMD'..."
exec $START_CMD
fi

0 comments on commit f64daaa

Please sign in to comment.