diff --git a/scripts/dashboards.sh b/scripts/dashboards.sh index 1f0a0c8..9c3a82c 100644 --- a/scripts/dashboards.sh +++ b/scripts/dashboards.sh @@ -11,13 +11,14 @@ set -o errexit -readonly HOST=$(bashio::config 'grafana_host') -readonly PORT=$(bashio::config 'grafana_port') -readonly USER=$(bashio::config 'grafana_user') -readonly PASS=$(bashio::config 'grafana_pass') -readonly DASHBOARDS_DIRECTORY="/dashboards" -readonly FOLDER_NAME=$(bashio::config 'grafana_folder_name') +HOST=$(bashio::config 'grafana_host') +PORT=$(bashio::config 'grafana_port') +USER=$(bashio::config 'grafana_user') +PASS=$(bashio::config 'grafana_pass') +DASHBOARDS_DIRECTORY="/dashboards" +FOLDER_NAME=$(bashio::config 'grafana_folder_name') +readonly HOST PORT USER PASS DASHBOARDS_DIRECTORY FOLDER_NAME main() { @@ -25,13 +26,12 @@ main() { URL="http://$HOST:$PORT" LOGIN="$USER:$PASS" - + case $task in backup) backup;; restore) restore;; *) exit 1;; esac - } @@ -42,9 +42,7 @@ backup() { dashboard_json=$(get_dashboard "$dashboard") if [[ -z "$dashboard_json" ]]; then - echo "ERROR: - Couldn't retrieve dashboard $dashboard. - " + echo "ERROR: Couldn't retrieve dashboard $dashboard." exit 1 fi @@ -57,10 +55,18 @@ backup() { restore() { bashio::log.info "Checking for Grafana folder: $FOLDER_NAME" - FLD=$(curl --silent --show-error \ + folders=$(curl --silent --show-error \ --user "$LOGIN" -H "Content-Type: application/json" \ - $URL/api/folders | jq ".[] | select(.title==\"$FOLDER_NAME\")") - + "$URL/api/folders") + + if [[ $folders == *"statusCode"* ]]; then + bashio::log.error "Error getting Grafana folders: $(echo "$folders" | jq -r .message)" + bashio::log.debug "$folders" + exit 1 + fi + + FLD=$(echo "$folders" | jq ".[] | select(.title==\"$FOLDER_NAME\")") + if [[ -z "$FLD" ]]; then bashio::log.info "Not found... creating" FLD=$(curl \ @@ -72,7 +78,7 @@ restore() { "$URL/api/folders") fi - FOLDER_ID=$(echo $FLD | jq -r .id) + FOLDER_ID=$(echo "$FLD" | jq -r .id) if [[ -z "$FOLDER_ID" ]]; then bashio::log.error "Could not determine Grafana folder id" @@ -123,5 +129,4 @@ list_dashboards() { cut -d '/' -f2 } - main "$@" \ No newline at end of file diff --git a/services/nginx/run b/services/nginx/run index 394e955..57bc216 100644 --- a/services/nginx/run +++ b/services/nginx/run @@ -1,5 +1,11 @@ #!/command/with-contenv bashio # -*- bash -*- # shellcheck shell=bash -mkdir /run/nginx + +bashio::log.info "Starting NGINX..." +if [ -f /run/nginx ]; then + rm -f /run/nginx +fi +mkdir -p /run/nginx + exec nginx -g 'daemon off;error_log /proc/1/fd/1 error;' \ No newline at end of file diff --git a/services/teslamate/run b/services/teslamate/run index eba00d9..56c196a 100644 --- a/services/teslamate/run +++ b/services/teslamate/run @@ -54,7 +54,7 @@ done # Import dashboards if bashio::config.true 'grafana_import_dashboards'; then - /dashboards.sh restore + /dashboards.sh restore || bashio::log.error "Failed to import dashboards" fi # Create the PostgreSQL database if it doesn't exist @@ -78,7 +78,7 @@ fi ulimit -n 1048576 -bashio::log.info "Starting TeslaMate" +bashio::log.info "Starting TeslaMate..." cd /opt/app exec $(/usr/bin/env sh) /entrypoint.sh bin/teslamate start