-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·93 lines (77 loc) · 3.27 KB
/
run.sh
File metadata and controls
executable file
·93 lines (77 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# Script to set up and run a 2PC transaction
echo "Setting up 2PC System..."
# Install dependencies for all services
echo "Installing dependencies..."
npm install
cd coordinator && npm install && cd ..
cd service1 && npm install && cd ..
cd service2 && npm install && cd ..
# Start PostgreSQL containers
echo "Starting PostgreSQL containers..."
echo "Stopping any existing containers first..."
docker-compose down
echo "Starting containers with updated configuration..."
docker-compose up -d
# Wait for PostgreSQL to be ready
echo "Waiting for PostgreSQL to be ready..."
sleep 10
# Start all Node.js applications in separate terminals
echo "Starting Node.js applications..."
# Start coordinator
echo "Starting coordinator service..."
gnome-terminal --title="Coordinator" -- bash -c "cd coordinator && node src/index.js" 2>/dev/null || \
xterm -T "Coordinator" -e "cd coordinator && node src/index.js" 2>/dev/null || \
osascript -e 'tell app "Terminal" to do script "cd '$(pwd)'/coordinator && node src/index.js"' 2>/dev/null || \
start cmd /k "cd coordinator && node src/index.js" 2>/dev/null || \
echo "Could not open a new terminal window for coordinator. Please start it manually."
# Start service1
echo "Starting user service..."
gnome-terminal --title="User Service" -- bash -c "cd service1 && node src/index.js" 2>/dev/null || \
xterm -T "User Service" -e "cd service1 && node src/index.js" 2>/dev/null || \
osascript -e 'tell app "Terminal" to do script "cd '$(pwd)'/service1 && node src/index.js"' 2>/dev/null || \
start cmd /k "cd service1 && node src/index.js" 2>/dev/null || \
echo "Could not open a new terminal window for user service. Please start it manually."
# Start service2
echo "Starting order service..."
gnome-terminal --title="Order Service" -- bash -c "cd service2 && node src/index.js" 2>/dev/null || \
xterm -T "Order Service" -e "cd service2 && node src/index.js" 2>/dev/null || \
osascript -e 'tell app "Terminal" to do script "cd '$(pwd)'/service2 && node src/index.js"' 2>/dev/null || \
start cmd /k "cd service2 && node src/index.js" 2>/dev/null || \
echo "Could not open a new terminal window for order service. Please start it manually."
# Wait for services to start
echo "Waiting for services to start..."
sleep 5
# Check if services are running
echo "Checking if services are running..."
MAX_RETRIES=10
RETRY_COUNT=0
while ! curl -s http://localhost:3000/transactions > /dev/null && [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
echo "Services are not ready yet. Retrying in 2 seconds..."
sleep 2
RETRY_COUNT=$((RETRY_COUNT+1))
done
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "Services failed to start. Please check the logs."
exit 1
fi
echo "All services are running!"
# Launch a sample transaction
echo "Launching a sample transaction..."
curl -X POST http://localhost:3000/transaction \
-H "Content-Type: application/json" \
-d '{
"user": {
"username": "john_doe",
"email": "john@example.com"
},
"order": {
"user_id": 1,
"product_name": "Smartphone",
"quantity": 1,
"total_price": 999.99
}
}'
echo -e "\n\nTransaction initiated. Check the logs for details."
echo "You can view all transactions by visiting: http://localhost:3000/transactions"
echo "You can run more transactions using the transactions.http file."