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