perf: replace mongosh ping with Python script for lightweight healthcheck
Signed-off-by: FuryL <748550450@qq.com>pull/225/head
parent
b0cb09c2ec
commit
fa60c402ad
@ -0,0 +1,6 @@
|
||||
FROM docker.io/mongo:latest
|
||||
|
||||
# install Python3, pip, pymongo for low memory usage healthcheck
|
||||
RUN apt-get update && \
|
||||
apt-get install -y python3 python3-pip python3-pymongo && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
@ -0,0 +1,24 @@
|
||||
from pymongo import MongoClient
|
||||
from pymongo.errors import PyMongoError
|
||||
import sys
|
||||
import json
|
||||
|
||||
try:
|
||||
client = MongoClient(
|
||||
"mongodb://localhost:27017",
|
||||
connectTimeoutMS=3000,
|
||||
serverSelectionTimeoutMS=5000,
|
||||
socketTimeoutMS=5000,
|
||||
directConnection=True,
|
||||
)
|
||||
|
||||
client.admin.command("ping")
|
||||
print(json.dumps({"ok": 1}))
|
||||
sys.exit(0)
|
||||
|
||||
except PyMongoError as e:
|
||||
print(json.dumps({
|
||||
"ok": 0,
|
||||
"error": str(e)
|
||||
}, ensure_ascii=False), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
Loading…
Reference in New Issue