diff options
Diffstat (limited to 'data')
-rw-r--r-- | data/collector_container/Dockerfile | 4 | ||||
-rw-r--r-- | data/healthcheck-mongodb.js | 7 | ||||
-rw-r--r-- | data/init-mongodb.js | 8 | ||||
-rw-r--r-- | data/mongodb_container/Dockerfile | 6 | ||||
-rwxr-xr-x | data/mongodb_entrypoint.sh | 4 |
5 files changed, 21 insertions, 8 deletions
diff --git a/data/collector_container/Dockerfile b/data/collector_container/Dockerfile index a9bb4e5..05bae7a 100644 --- a/data/collector_container/Dockerfile +++ b/data/collector_container/Dockerfile @@ -30,8 +30,8 @@ WORKDIR /app/ USER collector # Add healthcheck -HEALTHCHECK --interval=30s --timeout=15s --retries=1 --start-period=30s \ - CMD sh healthcheck.sh || bash -c 'kill -s 15 1 && (sleep 7; kill -s 9 1)' +HEALTHCHECK --interval=2m --timeout=15s --retries=1 --start-period=30s \ + CMD sh ./src/collector/healthcheck.sh COLLECTOR || bash -c 'kill -s 15 1 && (sleep 7; kill -s 9 1)' ENTRYPOINT ["uvicorn", "src.collector.main:app", "--host", "0.0.0.0", "--workers", "1", "--header", "server:collector"] diff --git a/data/healthcheck-mongodb.js b/data/healthcheck-mongodb.js new file mode 100644 index 0000000..64071e6 --- /dev/null +++ b/data/healthcheck-mongodb.js @@ -0,0 +1,7 @@ +// Get data from DB, check if data is equal to test +var healthcheck_status = db.healthcheck.findOne({"healthcheck": "ok"}); +print(healthcheck_status); +if (healthcheck_status["healthcheck"] == "ok"){ + exit(0); +} +exit(1); diff --git a/data/init-mongodb.js b/data/init-mongodb.js index 6057d84..054dfd1 100644 --- a/data/init-mongodb.js +++ b/data/init-mongodb.js @@ -1,8 +1,3 @@ - -// To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy). -// You can opt-out by running the disableTelemetry() command. -disableTelemetry() - // Create the DB by inserting some data db.REPLACE_COLLECTION.insertOne({init_key: "init_data"}) @@ -23,6 +18,9 @@ db.createUser( // Delete the init data db.REPLACE_COLLECTION.deleteOne({init_key: "init_data"}) +// Add healthcheck +db.healthcheck.insertOne({healthcheck: "ok"}) + // Disable the ad about monitoring db.disableFreeMonitoring() diff --git a/data/mongodb_container/Dockerfile b/data/mongodb_container/Dockerfile index 32ee43b..f37d2a3 100644 --- a/data/mongodb_container/Dockerfile +++ b/data/mongodb_container/Dockerfile @@ -19,9 +19,15 @@ RUN find / -xdev -perm /6000 -type f -exec chmod a-s {} \; || true COPY ./data/mongodb_entrypoint.sh /mongodb_entrypoint.sh COPY ./data/init-mongodb.js /init-mongodb.js +COPY ./data/healthcheck-mongodb.js /healthcheck-mongodb.js +COPY ./src/collector/healthcheck.sh /healthcheck.sh USER mongodb WORKDIR /data/db +# Add healthcheck +HEALTHCHECK --interval=30s --timeout=15s --retries=1 --start-period=30s \ + CMD sh /healthcheck.sh MONGODB || bash -c 'kill -s 15 1 && (sleep 7; kill -s 9 1)' + ENTRYPOINT ["bash", "/mongodb_entrypoint.sh"] diff --git a/data/mongodb_entrypoint.sh b/data/mongodb_entrypoint.sh index 7a81abc..81ed619 100755 --- a/data/mongodb_entrypoint.sh +++ b/data/mongodb_entrypoint.sh @@ -11,7 +11,8 @@ then sed -i "s/REPLACE_COLLECTION/$MONGODB_COLLECTION/g" /data/db/init-mongodb.js # Update and shutdown our DB with changes - /usr/bin/mongosh localhost:27015/production /data/db/init-mongodb.js + /usr/bin/mongosh --eval 'disableTelemetry()' localhost:27015/production /data/db/init-mongodb.js + # /usr/bin/mongosh localhost:27015/production /data/db/init-mongodb.js sleep 1 # Allow DB to shutdown /usr/bin/touch /data/db/user_exist rm /data/db/init-mongodb.js @@ -19,3 +20,4 @@ fi # Startup normally now with our user exec /usr/bin/mongod --nounixsocket --bind_ip_all --auth + |