Skip to content

Commit 6f8e612

Browse files
authored
chore(server): change mogo replica setting (#1930)
1 parent 241daac commit 6f8e612

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

docker-compose.dev.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ services:
2121

2222
reearth-mongo:
2323
image: mongo:7
24+
hostname: reearth-mongo
2425
ports:
2526
- 27017:27017
2627
volumes:
2728
- ${PWD}/tmp/mongo:/data/db
29+
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
30+
command: ["mongod", "--bind_ip_all", "--replSet", "rs0"]
2831
networks:
2932
- reearth
3033

mongo-init.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// MongoDB Replica Set Initialization Script
2+
// Initialize with localhost for reliability
3+
// Services will connect using directConnection=true
4+
5+
rs.initiate({
6+
_id: "rs0",
7+
members: [{ _id: 0, host: "localhost:27017" }],
8+
});
9+
10+
print("✓ Replica set initiated with localhost:27017");
11+
print("Services should connect with ?directConnection=true parameter");
12+
13+
rs.status();

server/.env.docker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This file is used when running the application in Docker
33

44
# Database connection (Docker service name)
5-
REEARTH_DB=mongodb://reearth-mongo
5+
REEARTH_DB=mongodb://reearth-mongo/?directConnection=true
66

77
# Server host (bind to all interfaces in Docker)
88
REEARTH_SERVERHOST=0.0.0.0

server/Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,17 @@ destroy:
231231
@read -p "Are you sure you want to continue? [y/N] " -n 1 -r; \
232232
echo; \
233233
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
234-
docker stop $(docker ps -q); \
234+
containers=$$(docker ps -q); \
235+
if [ -n "$$containers" ]; then \
236+
docker stop $$containers; \
237+
else \
238+
echo "No running containers to stop."; \
239+
fi; \
235240
docker system prune -a --volumes -f; \
236241
docker network prune -f; \
237242
echo "✓ All Docker resources have been removed"; \
238243
echo "==== Removing data directory (requires sudo password) ===="; \
239-
sudo rm -rf tmp/gcs tmp/mongo
244+
sudo rm -rf tmp/gcs tmp/mongo; \
240245
echo "✓ All data resources have been cleared"; \
241246
else \
242247
echo "✗ Operation cancelled"; \

0 commit comments

Comments
 (0)