From d322c38c11783559df53074ca9650a42a4f9934a Mon Sep 17 00:00:00 2001 From: Bo QIU <35757521+boqiu@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:25:07 +0800 Subject: [PATCH] Add script for dev test purpose (#288) * Add script for local startup * requires .env file * fix bash syntax * exit on exception --- .gitignore | 1 + run/zgs.sh | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 run/zgs.sh diff --git a/.gitignore b/.gitignore index 37d0c30..7eb8fcc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ tests/**/__pycache__ tests/tmp/** .vscode/*.json /0g-storage-contracts-dev +/run/.env diff --git a/run/zgs.sh b/run/zgs.sh new file mode 100755 index 0000000..9d2f1a7 --- /dev/null +++ b/run/zgs.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +if [[ $# -eq 0 ]]; then + echo "Usage: zgs.sh start | stop | info | clean" + exit 1 +fi + +pid=`ps -ef | grep zgs_node | grep -v grep | awk '{print $2}'` + +case $1 in + + start) + if [[ "$pid" = "" ]]; then + if [ ! -f .env ]; then + echo ".env file not found" + exit 1 + fi + + source .env + + if [[ "$ZGS_NODE__MINER_KEY" = "" ]]; then + echo "ZGS_NODE__MINER_KEY not specified in .env file" + exit 1 + fi + + if [[ "$ZGS_NODE__BLOCKCHAIN_RPC_ENDPOINT" = "" ]]; then + echo "ZGS_NODE__BLOCKCHAIN_RPC_ENDPOINT not specified in .env file" + exit 1 + fi + + nohup ../target/release/zgs_node --config config-testnet-turbo.toml \ + --log-config-file log_config_debug \ + --miner-key $ZGS_NODE__MINER_KEY \ + --blockchain-rpc-endpoint $ZGS_NODE__BLOCKCHAIN_RPC_ENDPOINT & + + echo "Storage node started ..." + else + echo "Storage node already started, pid = $pid" + exit 1 + fi + ;; + + stop) + if [[ "$pid" = "" ]]; then + echo "Storage node not started yet" + exit 1 + else + kill $pid + echo "Storage node terminated, pid = $pid" + fi + ;; + + info) + if [[ "$pid" = "" ]]; then + echo "Storage node not started yet" + exit 1 + else + curl -X POST --data '{"jsonrpc":"2.0","method":"zgs_getStatus","params":[],"id":1}' \ + -H "Content-Type: application/json" http://127.0.0.1:5678 | jq -C ".result" + fi + ;; + + clean) + rm -rf nohup.out db log + ;; + + *) + echo "Usage: zgs.sh start | stop | info | clean" + ;; + +esac