Compare commits

...

1 Commits

Author SHA1 Message Date
Zomatree
d9643ebd8d feat: initiate mongo replset by default
Signed-off-by: Zomatree <me@zomatree.live>
2026-03-29 05:37:43 +01:00
5 changed files with 27 additions and 3 deletions

View File

@@ -4,7 +4,7 @@
[database]
# MongoDB connection URL
# Defaults to the container name specified in self-hosted
mongodb = "mongodb://127.0.0.1:27017"
mongodb = "mongodb://127.0.0.1:27017?directConnection=true&replicaSet=rs0"
# Redis connection URL
# Defaults to the container name specified in self-hosted
redis = "redis://127.0.0.1:6379/"

View File

@@ -8,10 +8,29 @@ services:
# MongoDB
database:
image: mongo
command: ["--replSet", "rs0", "--bind_ip_all"]
ports:
- "27017:27017"
volumes:
- ./.data/db:/data/db
- ./scripts/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
healthcheck:
test: >
mongosh --quiet --eval "
try {
const status = rs.status();
if (status.ok === 1 && status.members[0].stateStr === 'PRIMARY') {
quit(0);
} else {
quit(1);
}
} catch (e) {
quit(1);
}"
interval: 5s
timeout: 5s
retries: 10
start_period: 10s
ulimits:
nofile:
soft: 65536

View File

@@ -1,5 +1,5 @@
[database]
mongodb = "mongodb://localhost"
mongodb = "mongodb://localhost?directConnection=true&replicaSet=rs0"
redis = "redis://localhost/"
[rabbit]

View File

@@ -4,7 +4,7 @@ disable_events_dont_use = false
[database]
# MongoDB connection URL
# Defaults to the container name specified in self-hosted
mongodb = "mongodb://database"
mongodb = "mongodb://database?directConnection=true&replicaSet=rs0"
# Redis connection URL
# Defaults to the container name specified in self-hosted
redis = "redis://redis/"

5
scripts/mongo-init.js Normal file
View File

@@ -0,0 +1,5 @@
try {
rs.status();
} catch (e) {
rs.initiate({ _id: "rs0", members: [{ _id: 0, host: "localhost:27017" }] });
}