Skip to content

Commit 4e07abf

Browse files
committed
feat: add run_localnet.sh script
1 parent 5cc7fc9 commit 4e07abf

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

run_localnet.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
CONFIG_PATH="./.github/actions/start-local-network/config.yaml"
6+
COMPOSE_PATH="./.github/actions/start-local-network/gas_station_compose.yml"
7+
CONFIG_BACKUP="$CONFIG_PATH.backup"
8+
IOTA_LOG="iota_network.log"
9+
10+
if [ "$1" == "start" ]; then
11+
echo "Starting local IOTA network with gas station..."
12+
13+
# Backup config file
14+
if [ -f "$CONFIG_BACKUP" ]; then
15+
echo "Backup already exists, skipping backup"
16+
else
17+
cp "$CONFIG_PATH" "$CONFIG_BACKUP"
18+
echo "Backed up config to $CONFIG_BACKUP"
19+
fi
20+
21+
# Start PostgreSQL
22+
echo "Starting PostgreSQL..."
23+
docker start postgres || docker run -d --name postgres -e POSTGRES_PASSWORD=postgrespw -e POSTGRES_INITDB_ARGS="-U postgres" -p 5432:5432 postgres:15 -c max_connections=1000
24+
25+
# Start IOTA network
26+
echo "Starting IOTA network..."
27+
RUST_LOG="info,consensus=warn,iota_core=warn,fastcrypto_tbls=off,iota_indexer=warn,iota_data_ingestion_core=error,iota_graphql_rpc=warn" iota start --force-regenesis --with-faucet --with-indexer --with-graphql >> "$IOTA_LOG" 2>&1 &
28+
IOTA_PID=$!
29+
30+
# Use all 0's private key for gas station
31+
keyWithFlag="AJmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ" # iotaprivkey1qzvenxvenxvenxvenxvenxvenxvenxvenxvenxvenxvenxvenxvejj8c0wa
32+
address="0xa7c2cf9d8f8d95ff69d7a598c49c77acc36253f496f064a533ad306879b40bfa"
33+
34+
echo "Setting keypair in config..."
35+
sed -i "s|<keypair>|$keyWithFlag|g" "$CONFIG_PATH"
36+
37+
echo "Waiting for network to start and requesting faucet coins..."
38+
success=false
39+
for i in {1..10}; do
40+
sleep 3
41+
if iota client faucet --url http://127.0.0.1:9123/gas --address $address >/dev/null 2>&1; then
42+
success=true
43+
break
44+
fi
45+
done
46+
if ! $success; then
47+
echo "Failed to request faucet coins after 30 seconds"
48+
exit 1
49+
fi
50+
51+
echo "Starting Gas Station..."
52+
# Set gas station auth
53+
export GAS_STATION_AUTH=test
54+
docker compose -f "$COMPOSE_PATH" -p start-local-network up -d
55+
56+
echo "Local network and gas station started successfully!"
57+
echo "IOTA PID: $IOTA_PID"
58+
echo "Logs are being written to $IOTA_LOG"
59+
echo "To view logs: $0 logs"
60+
echo "To stop, run: $0 stop"
61+
62+
elif [ "$1" == "stop" ]; then
63+
echo "Stopping local IOTA network and gas station..."
64+
65+
# Stop gas station
66+
echo "Stopping Gas Station..."
67+
# Flush Redis data before stopping
68+
redis-cli FLUSHALL || echo "Could not flush Redis data"
69+
docker compose -f "$COMPOSE_PATH" -p start-local-network down
70+
71+
# Remove Redis volume to clean persisted data
72+
echo "Removing Redis data volume..."
73+
docker volume rm start-local-network_redis_data || echo "Redis volume not found or already removed"
74+
75+
# Stop IOTA network
76+
echo "Stopping IOTA network..."
77+
pkill -f "iota start" || echo "IOTA process not found or already stopped"
78+
79+
# Stop PostgreSQL
80+
echo "Stopping PostgreSQL..."
81+
docker stop postgres || echo "PostgreSQL not running"
82+
83+
# Restore config
84+
if [ -f "$CONFIG_BACKUP" ]; then
85+
mv "$CONFIG_BACKUP" "$CONFIG_PATH"
86+
echo "Restored config from backup"
87+
else
88+
echo "No backup found, config may have been manually modified"
89+
fi
90+
91+
# Clean up log file
92+
if [ -f "$IOTA_LOG" ]; then
93+
rm "$IOTA_LOG"
94+
echo "Removed log file $IOTA_LOG"
95+
fi
96+
97+
echo "Local network and gas station stopped."
98+
99+
elif [ "$1" == "logs" ]; then
100+
if [ -f "$IOTA_LOG" ]; then
101+
tail -f "$IOTA_LOG"
102+
else
103+
echo "Log file $IOTA_LOG not found. Start the network first."
104+
fi
105+
106+
else
107+
echo "Usage: $0 start|stop|logs"
108+
echo " start: Start the local IOTA network with gas station"
109+
echo " stop: Stop the local IOTA network and gas station"
110+
echo " logs: View the latest IOTA network logs (follow mode)"
111+
fi

0 commit comments

Comments
 (0)