From 73453715e78700abc3fa7250f773e32ad38ab9b0 Mon Sep 17 00:00:00 2001 From: Marcio Granzotto Date: Thu, 20 Apr 2023 01:30:50 -0300 Subject: [PATCH 1/2] Fix MongoDB failing to init --- nightscout/config.json | 1 - nightscout/rootfs/etc/services.d/mongodb/finish | 10 ++++++++++ nightscout/rootfs/etc/services.d/mongodb/run | 14 ++++++++++++++ nightscout/rootfs/etc/services.d/nightscout/run | 1 - 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100755 nightscout/rootfs/etc/services.d/mongodb/finish create mode 100755 nightscout/rootfs/etc/services.d/mongodb/run diff --git a/nightscout/config.json b/nightscout/config.json index 2db99f5..649095e 100644 --- a/nightscout/config.json +++ b/nightscout/config.json @@ -9,7 +9,6 @@ "startup": "services", "init": "false", "boot": "auto", - "image": "marciogranzotto/image-{arch}-addon-nightscout", "hassio_role": "default", "ports": { "5423/tcp": 5423 diff --git a/nightscout/rootfs/etc/services.d/mongodb/finish b/nightscout/rootfs/etc/services.d/mongodb/finish new file mode 100755 index 0000000..68c6ffc --- /dev/null +++ b/nightscout/rootfs/etc/services.d/mongodb/finish @@ -0,0 +1,10 @@ +#!/usr/bin/with-contenv bash +# ============================================================================== +# Gracefully stop MongoDB +# ============================================================================== + +# Send the SIGTERM signal to MongoDB to allow it to perform a graceful shutdown +pkill -SIGTERM mongod + +# Wait for MongoDB to shut down +timeout 30 sh -c 'until [ "$(pgrep mongod)" = "" ]; do sleep 1; done' diff --git a/nightscout/rootfs/etc/services.d/mongodb/run b/nightscout/rootfs/etc/services.d/mongodb/run new file mode 100755 index 0000000..90ca0b6 --- /dev/null +++ b/nightscout/rootfs/etc/services.d/mongodb/run @@ -0,0 +1,14 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Home Assistant Add-on: Nightscout +# Runs MongoDB +# ============================================================================== + +bashio::log.info "Starting MongoDB..." + +# Set the data directory and bind IP address +export MONGODB_DBPATH="/var/lib/mongodb" +export MONGODB_BIND_IP="127.0.0.1" + +# Start MongoDB with the specified options +exec s6-setuidgid mongodb /usr/bin/mongod --dbpath "$MONGODB_DBPATH" --bind_ip "$MONGODB_BIND_IP" diff --git a/nightscout/rootfs/etc/services.d/nightscout/run b/nightscout/rootfs/etc/services.d/nightscout/run index dac8b0d..a8359a8 100755 --- a/nightscout/rootfs/etc/services.d/nightscout/run +++ b/nightscout/rootfs/etc/services.d/nightscout/run @@ -7,7 +7,6 @@ declare -a options # Wait for MongoDB to become available -service mongodb start bashio::net.wait_for 27017 bashio::log.info 'Starting the Nightscout server...' From 430b6d14d04418b4011f9986af0dd64537cb45f9 Mon Sep 17 00:00:00 2001 From: Marcio Granzotto Rodrigues Date: Thu, 20 Apr 2023 01:32:24 -0300 Subject: [PATCH 2/2] Update config.json --- nightscout/config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/nightscout/config.json b/nightscout/config.json index 649095e..2db99f5 100644 --- a/nightscout/config.json +++ b/nightscout/config.json @@ -9,6 +9,7 @@ "startup": "services", "init": "false", "boot": "auto", + "image": "marciogranzotto/image-{arch}-addon-nightscout", "hassio_role": "default", "ports": { "5423/tcp": 5423