├── netdata ├── README.md ├── .shellcheckrc ├── icon.png ├── logo.png ├── rootfs │ ├── usr │ │ └── sbin │ │ │ └── health.sh │ └── opt │ │ └── netdata-hass-addon │ │ ├── common.bash │ │ ├── prepare_image.sh │ │ └── run.sh ├── Dockerfile ├── config.yaml ├── CHANGELOG.md └── DOCS.md ├── .github ├── FUNDING.yml └── workflows │ └── ci.yaml ├── tests ├── options.json ├── docker-compose.yaml └── test.sh ├── repository.yaml ├── .vscode └── settings.json ├── renovate.json ├── LICENSE └── README.md /netdata/README.md: -------------------------------------------------------------------------------- 1 | ./DOCS.md -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [felipecrs] 2 | -------------------------------------------------------------------------------- /netdata/.shellcheckrc: -------------------------------------------------------------------------------- 1 | external-sources=true 2 | -------------------------------------------------------------------------------- /netdata/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/felipecrs/netdata-hass-addon/HEAD/netdata/icon.png -------------------------------------------------------------------------------- /netdata/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/felipecrs/netdata-hass-addon/HEAD/netdata/logo.png -------------------------------------------------------------------------------- /tests/options.json: -------------------------------------------------------------------------------- 1 | { 2 | "hostname": "homeassistant", 3 | "netdata_claim_url": "https://app.netdata.cloud" 4 | } -------------------------------------------------------------------------------- /repository.yaml: -------------------------------------------------------------------------------- 1 | # https://developers.home-assistant.io/docs/add-ons/repository#repository-configuration 2 | name: Netdata Home Assistant add-on repository 3 | url: https://github.com/felipecrs/netdata-hass-addon 4 | maintainer: Felipe Santos 5 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[yaml][json][jsonc][markdown]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "prettier.proseWrap": "always", 6 | "docker.languageserver.formatter.ignoreMultilineInstructions": true, 7 | "files.trimTrailingWhitespace": true 8 | } 9 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | ci: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v6 16 | - uses: frenck/action-addon-linter@v2.21 17 | with: 18 | path: ./netdata 19 | - run: tests/test.sh 20 | -------------------------------------------------------------------------------- /netdata/rootfs/usr/sbin/health.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # shellcheck source=../../opt/netdata-hass-addon/common.bash 4 | source /opt/netdata-hass-addon/common.bash 5 | 6 | get_config netdata_healthcheck_target 7 | if [[ -n "${netdata_healthcheck_target}" ]]; then 8 | export NETDATA_HEALTHCHECK_TARGET="${netdata_healthcheck_target}" 9 | fi 10 | 11 | # Call the original Netdata docker health check 12 | exec /opt/netdata-hass-addon/health.sh.orig "${@}" 13 | -------------------------------------------------------------------------------- /netdata/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ghcr.io/netdata/netdata:v2.8.4 2 | 3 | # add-ons normally run as root 4 | # hadolint ignore=DL3002 5 | USER root 6 | 7 | # this could have been done with RUN --mount, but HAOS doesn't use buildkit 8 | COPY rootfs/opt/netdata-hass-addon/prepare_image.sh rootfs/opt/netdata-hass-addon/common.bash /opt/netdata-hass-addon/ 9 | RUN ["/opt/netdata-hass-addon/prepare_image.sh"] 10 | 11 | COPY rootfs / 12 | 13 | ENTRYPOINT ["/opt/netdata-hass-addon/run.sh"] 14 | -------------------------------------------------------------------------------- /netdata/rootfs/opt/netdata-hass-addon/common.bash: -------------------------------------------------------------------------------- 1 | set -euo pipefail 2 | shopt -s inherit_errexit 3 | 4 | function echo_error() { 5 | echo "ERROR:" "${@}" >&2 6 | } 7 | 8 | function error() { 9 | echo_error "${@}" 10 | exit 1 11 | } 12 | 13 | function get_config() { 14 | local -r name="$1" 15 | local value 16 | 17 | value=$(jq -r ".${name}" /data/options.json) 18 | 19 | if [[ "${value}" == "null" ]]; then 20 | value="" 21 | fi 22 | declare -g "${name}=${value}" 23 | } 24 | -------------------------------------------------------------------------------- /tests/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | netdata: 3 | build: ../netdata 4 | volumes: 5 | - /var/run/docker.sock:/var/run/docker.sock 6 | - ./options.json:/data/options.json 7 | pid: host 8 | network_mode: host 9 | # For some reason, even though these capabilities are enough in my machine, 10 | # they are not enough in GitHub Actions, but privileged does the trick. 11 | # cap_add: 12 | # - SYS_PTRACE 13 | # - SYS_ADMIN 14 | # - SYS_RAWIO 15 | privileged: true 16 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["config:recommended"], 4 | "dependencyDashboard": true, 5 | "packageRules": [ 6 | { 7 | "description": "Automerge non-major updates", 8 | "matchUpdateTypes": ["minor", "patch"], 9 | "automerge": true 10 | } 11 | ], 12 | "enabledManagers": ["github-actions", "regex"], 13 | "customManagers": [ 14 | { 15 | "customType": "regex", 16 | "fileMatch": ["^netdata/Dockerfile$", "^netdata/config.yaml$"], 17 | "matchStrings": [ 18 | "FROM ghcr.io/netdata/netdata:v(?.+)\\n", 19 | "version: (?.+)\\n" 20 | ], 21 | "depNameTemplate": "netdata/netdata", 22 | "datasourceTemplate": "github-releases" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Felipe Santos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /netdata/rootfs/opt/netdata-hass-addon/prepare_image.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # shellcheck source=./common.bash 4 | source /opt/netdata-hass-addon/common.bash 5 | 6 | # the upstream image may move these scripts in the future, this is a safeguard 7 | if [[ -x /usr/sbin/health.sh ]]; then 8 | # relocate the original health check script so we can put ours in its place 9 | mv -fv /usr/sbin/health.sh /opt/netdata-hass-addon/health.sh.orig 10 | else 11 | error 'Could not find Netdata health check script at /usr/sbin/health.sh' 12 | fi 13 | 14 | if [[ ! -x /usr/sbin/run.sh ]]; then 15 | error 'Could not find find Netdata entrypoint script at /usr/sbin/run.sh' 16 | fi 17 | 18 | set -x 19 | 20 | apt-get update 21 | 22 | # curl: needeed by run.sh 23 | # smartmontools: useful enough for Home Assistant to have it as a default dependency 24 | # nvme-cli: useful enough for Home Assistant to have it as a default dependency 25 | # apcupsd: useful enough for Home Assistant to have it as a default dependency 26 | apt-get install -y --no-install-recommends curl smartmontools nvme-cli apcupsd 27 | 28 | # clean up apt cache 29 | rm -rf /var/lib/apt/lists/* 30 | -------------------------------------------------------------------------------- /netdata/config.yaml: -------------------------------------------------------------------------------- 1 | # https://developers.home-assistant.io/docs/add-ons/configuration#add-on-config 2 | name: Netdata 3 | version: v2.8.4 4 | slug: netdata 5 | description: 6 | Monitor your servers, containers, and applications, in high-resolution and in 7 | real-time 8 | url: "https://github.com/felipecrs/netdata-hass-addon/tree/master/netdata" 9 | arch: 10 | - armhf 11 | - armv7 12 | - aarch64 13 | - amd64 14 | - i386 15 | options: 16 | hostname: homeassistant 17 | netdata_claim_url: https://app.netdata.cloud 18 | netdata_claim_token: "" 19 | netdata_claim_rooms: "" 20 | netdata_extra_deb_packages: "" 21 | netdata_healthcheck_target: "" 22 | schema: 23 | hostname: str 24 | netdata_claim_url: str 25 | netdata_claim_token: str 26 | netdata_claim_rooms: str 27 | netdata_extra_deb_packages: str 28 | netdata_healthcheck_target: str 29 | startup: services 30 | ingress: true 31 | ingress_port: 19999 32 | ingress_stream: true 33 | init: false 34 | panel_icon: mdi:leaf 35 | panel_title: Netdata 36 | host_pid: true 37 | host_network: true 38 | host_dbus: true 39 | apparmor: false 40 | journald: true 41 | docker_api: true 42 | # For smartctl 43 | full_access: true 44 | privileged: 45 | - SYS_PTRACE 46 | - SYS_ADMIN 47 | # To allow run.sh create mount points and for smartctl 48 | - SYS_RAWIO 49 | map: 50 | - addon_config:rw 51 | # To allow run.sh migrate from home assistant config dir to add-on config 52 | - homeassistant_config:rw 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | ⭐Please star this add-on in GitHub if it helps you!⭐ 3 |

4 | 5 | # Home Assistant Add-on: Netdata 6 | 7 | _Monitor your servers, containers, and applications, in high-resolution and in 8 | real-time._ 9 | 10 | Learn more about Netdata at their 11 | [official website](https://www.netdata.cloud/). 12 | 13 | ![Netdata Home Assistant add-on](https://github.com/felipecrs/netdata-hass-addon/assets/29582865/535dcb73-c556-4369-aadd-a2d32425b83c) 14 | 15 | [![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Ffelipecrs%2Fnetdata-hass-addon) 16 | 17 | ![Supports aarch64 Architecture][aarch64-shield] 18 | ![Supports amd64 Architecture][amd64-shield] 19 | ![Supports armhf Architecture][armhf-shield] 20 | ![Supports armv7 Architecture][armv7-shield] 21 | ![Supports i386 Architecture][i386-shield] 22 | 23 | [aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg 24 | [amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg 25 | [armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg 26 | [armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg 27 | [i386-shield]: https://img.shields.io/badge/i386-yes-green.svg 28 | 29 | ## Get started 30 | 31 | See the documentation [here](netdata/DOCS.md). 32 | 33 | ## Credits 34 | 35 | While not a fork, this add-on was inspired by 36 | and 37 | . Thank you! 38 | -------------------------------------------------------------------------------- /netdata/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | [Click here to view the release notes of Netdata itself](https://github.com/netdata/netdata/releases). 4 | 5 | ### v2.6.0-addon.0 6 | 7 | - Remove workaround for Netdata not resolving container names, as it was fixed in Netdata v2.6.0 8 | 9 | ### v2.5.4-addon.2 10 | 11 | - Revert the _Fail on initialization if Watchdog is not enabled_ change, which was not necessary after all 12 | 13 | ### v2.5.4-addon.1 14 | 15 | - Fix the cleanup old Netdata images operation causing the add-on to fail on initialization if there was nothing to clean up 16 | - Fail on initialization if _Watchdog_ is not enabled 17 | - Revert the _Add a timeout for the cleanup old Netdata images operation_ change, which was not necessary after all 18 | 19 | ### v2.5.4-addon.0 20 | 21 | - Add a timeout for the cleanup old Netdata images operation to avoid blocking the add-on startup indefinitely 22 | 23 | ### v2.5.2-addon.0 24 | 25 | - Fix Netdata version still in 2.5.1 26 | 27 | ### v2.5.1-addon.3 28 | 29 | - Add check for when _Protection mode_ was not disabled 30 | - Avoid cleaning up Netdata images on initialization twice (before and after setting up the `/host` mounts) 31 | - Improve logs with fewer debug messages and more descriptive messages 32 | 33 | ### v2.5.1-addon.2 34 | 35 | - Remove dependency on Docker CLI 36 | - This makes the installation and update of the add-on considerably faster 37 | - And allowed to remove part of the workaround introduced in the last version, as realized [here](https://github.com/netdata/netdata/pull/20283#issuecomment-2881491522). 38 | 39 | ### v2.5.1-addon.1 40 | 41 | - Fix Netdata not resolving container names, fixes [#66](https://github.com/felipecrs/netdata-hass-addon/issues/66) 42 | - This works around a bug in Netdata itself, and I plan to upstream the fix at some point 43 | 44 | ### v2.5.1-addon.0 45 | 46 | - Delete previous Netdata image versions on startup, fixes [#65](https://github.com/felipecrs/netdata-hass-addon/issues/65) 47 | - This is a workaround for a [bug](https://github.com/home-assistant/supervisor/issues/3223) in Home Assistant Supervisor 48 | - Pull Netdata from GitHub Container Registry rather than from Docker Hub 49 | - Docker Hub has pull restrictions that GitHub Container Registry does not 50 | -------------------------------------------------------------------------------- /tests/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | 5 | script_dir=$(dirname "$0") 6 | readonly script_dir 7 | 8 | cd "${script_dir}" 9 | 10 | # HAOS apparently doesn't use buildkit 11 | DOCKER_BUILDKIT=0 docker compose build 12 | 13 | trap 'docker compose down' EXIT 14 | 15 | if docker compose up --wait; then 16 | echo "Container started healthily" >&2 17 | else 18 | docker compose logs --no-log-prefix 19 | echo "Container failed to start healthily, see logs above" >&2 20 | exit 1 21 | fi 22 | 23 | if container_os_release=$(docker compose exec -T netdata cat /host/etc/os-release); then 24 | echo "File /host/etc/os-release exists in the container" >&2 25 | else 26 | echo "File /host/etc/os-release does not exist in the container" >&2 27 | exit 1 28 | fi 29 | 30 | host_os_release=$(cat /etc/os-release) 31 | if [[ "${container_os_release}" == "${host_os_release}" ]]; then 32 | echo "File /host/etc/os-release in the container matches the host" >&2 33 | else 34 | echo "File /host/etc/os-release in the container does not match the host" >&2 35 | exit 1 36 | fi 37 | 38 | if container_cgroup_max_depth=$(docker compose exec -T netdata cat /host/sys/fs/cgroup/cgroup.max.depth); then 39 | echo "File /host/sys/fs/cgroup/cgroup.max.depth exists in the container" >&2 40 | else 41 | echo "File /host/sys/fs/cgroup/cgroup.max.depth does not exist in the container" >&2 42 | exit 1 43 | fi 44 | 45 | host_cgroup_max_depth=$(cat /sys/fs/cgroup/cgroup.max.depth) 46 | if [[ "${container_cgroup_max_depth}" == "${host_cgroup_max_depth}" ]]; then 47 | echo "File /host/sys/fs/cgroup/cgroup.max.depth in the container matches the host" >&2 48 | else 49 | echo "File /host/sys/fs/cgroup/cgroup.max.depth in the container does not match the host" >&2 50 | exit 1 51 | fi 52 | 53 | if docker compose down; then 54 | echo "Container stopped and removed successfully" >&2 55 | else 56 | echo "Container failed to stop and remove" >&2 57 | exit 1 58 | fi 59 | 60 | # There is a bug where the container can mess with the host cgroups upon removal, 61 | # this should help catch it 62 | if new_host_cgroup_max_depth=$(cat /sys/fs/cgroup/cgroup.max.depth) && [[ "${new_host_cgroup_max_depth}" == "${host_cgroup_max_depth}" ]]; then 63 | echo "Host cgroup max depth is unchanged after container removal" >&2 64 | else 65 | echo "Host cgroup max depth is changed after container removal" >&2 66 | exit 1 67 | fi 68 | -------------------------------------------------------------------------------- /netdata/DOCS.md: -------------------------------------------------------------------------------- 1 | # Home Assistant Add-on: Netdata 2 | 3 | _Monitor your servers, containers, and applications, in high-resolution and in 4 | real-time._ 5 | 6 | Learn more about Netdata at their 7 | [official website](https://www.netdata.cloud/). 8 | 9 | ![Netdata Home Assistant add-on](https://github.com/felipecrs/netdata-hass-addon/assets/29582865/535dcb73-c556-4369-aadd-a2d32425b83c) 10 | 11 | ## Installation 12 | 13 | Follow these steps to get the add-on installed on your system: 14 | 15 | 1. Click here: 16 | 17 | [![Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.](https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg)](https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Ffelipecrs%2Fnetdata-hass-addon) 18 | 19 | 1. Scroll down the page to find the new repository, and click in the new add-on 20 | named **_Netdata_**. 21 | 1. Click in the **_INSTALL_** button. 22 | 23 | ## Using 24 | 25 | 1. Disable _Protection Mode_ (the add-on cannot function otherwise). 26 | 1. Start the add-on. 27 | 28 | ## Configuring Netdata 29 | 30 | The Netdata configuration files are located in `/addon_configs/bc277197_netdata/netdata`. You can edit 31 | them directly. 32 | 33 | If you are using the _Advanced SSH & Web Terminal_ add-on with protection mode 34 | disabled, you can also use Netdata's `edit-config` helper. Example: 35 | 36 | ```console 37 | docker exec -it -w /etc/netdata addon_bc277197_netdata ./edit-config charts.d.conf 38 | ``` 39 | 40 | **Note**: _Remember to restart the add-on when the Netdata configuration files 41 | are changed._ 42 | 43 | ## Configuring the add-on 44 | 45 | The add-on has some optional configurations that can be used to customize it. 46 | 47 | **Note**: _Remember to restart the add-on when the configuration is changed._ 48 | 49 | ### Option: `netdata_claim_url` 50 | 51 | The Netdata Claim URL to use when connecting to the Netdata Cloud. The default 52 | is `https://app.netdata.cloud`, which is the official Netdata Cloud. 53 | 54 | ### Option: `netdata_claim_token` 55 | 56 | The Netdata Claim Token to use when connecting to the Netdata Cloud. You can get 57 | yours on . 58 | 59 | ![First step](https://github.com/hassio-addons/addon-ssh/assets/29582865/97b28b92-14f5-4232-88d4-f305de45a922) 60 | ![Second step](https://github.com/hassio-addons/addon-ssh/assets/29582865/9dfd2b72-9e1f-4f3e-87a0-a6e7d3761c23) 61 | 62 | ### Option: `netdata_claim_rooms` 63 | 64 | The Netdata Claim Rooms to use when connecting to the Netdata Cloud. You can get 65 | yours on . 66 | 67 | ![First step](https://github.com/hassio-addons/addon-ssh/assets/29582865/97b28b92-14f5-4232-88d4-f305de45a922) 68 | ![Second step](https://github.com/hassio-addons/addon-ssh/assets/29582865/7ce5bb97-903a-4778-8304-a2fa433c77b1) 69 | 70 | ### Option: `netdata_extra_deb_packages` 71 | 72 | Installs extra packages using Debian's package manager. For example: `apcupsd`. 73 | Refer to 74 | . 75 | 76 | Note that `smartmontools` and `nvme-cli` comes preinstalled already. 77 | 78 | ### Option: `netdata_healthcheck_target` 79 | 80 | Allows to control how the docker health checks from Netdata run. For example: 81 | `cli`. Refer to 82 | . 83 | 84 | ## Signing-in to Netdata Cloud from within the add-on 85 | 86 | When opening the Netdata web interface, you'll be prompted to sign-in to Netdata 87 | Cloud. 88 | 89 | **There's no need to do that**, and you can just click _Skip and use the 90 | dashboard anonymously_ instead. 91 | 92 | Unfortunately, 93 | [Netdata v2 provides no option to disable such annoyance](https://github.com/netdata/netdata/issues/18964). 94 | 95 | That said, the sign-in functionality will not work when accessing the Netdata 96 | interface through the Home Assistant interface. 97 | 98 | However, the add-on also exposes the Netdata web interface on port `19999`, 99 | which you can access from your browser: 100 | 101 | ``` 102 | http://:19999 103 | ``` 104 | 105 | And the sign-in button will work there. 106 | 107 | ## Configuring the [Netdata integration](https://www.home-assistant.io/integrations/netdata/) 108 | 109 | ```yaml 110 | # Example configuration.yaml entry 111 | sensor: 112 | - platform: netdata 113 | ``` 114 | 115 | You do not need to configure `host`, `port`, or `name`. The defaults will work. 116 | 117 | Read more on how to configure the Netdata integration 118 | [here](https://www.home-assistant.io/integrations/netdata/). 119 | -------------------------------------------------------------------------------- /netdata/rootfs/opt/netdata-hass-addon/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # shellcheck source=./common.bash 4 | source /opt/netdata-hass-addon/common.bash 5 | 6 | docker_sock='/var/run/docker.sock' 7 | 8 | # Gets the current/parent container id on the host. 9 | # Originally taken from https://github.com/felipecrs/docker-on-docker-shim/blob/90185d4391fb8863e1152098f07a95febbe79dba/dond 10 | function set_container_id() { 11 | local result 12 | 13 | local mount_info_lines=() 14 | readarray -t mount_info_lines &2 49 | 50 | if [[ ! -S "${docker_sock}" ]]; then 51 | error "This add-on needs 'Protection mode' to be disabled in the add-on page" 52 | fi 53 | 54 | # We cannot specify arbitrary volume mounts for add-ons, so we have to use this trick. 55 | if ! mountpoint --quiet /host/etc/os-release; then 56 | echo "Setting up /host mounts..." >&2 57 | 58 | set_container_id 59 | set_container_root_on_host 60 | 61 | set -x 62 | 63 | # Mount /proc from host to /host/proc as readonly with nsenter 64 | mkdir -p /host/proc 65 | nsenter --target 1 --mount -- \ 66 | mount --bind --read-only /proc "${container_root_on_host}/host/proc" 67 | 68 | # Same for /sys and /sys/fs/cgroup 69 | mkdir -p /host/sys 70 | nsenter --target 1 --mount -- \ 71 | mount --bind --read-only /sys "${container_root_on_host}/host/sys" 72 | nsenter --target 1 --mount -- \ 73 | mount --bind --read-only /sys/fs/cgroup "${container_root_on_host}/host/sys/fs/cgroup" 74 | 75 | # Same for /etc/passwd 76 | mkdir -p /host/etc 77 | touch /host/etc/passwd 78 | nsenter --target 1 --mount -- \ 79 | mount --bind --read-only /etc/passwd "${container_root_on_host}/host/etc/passwd" 80 | 81 | # Same for /etc/group 82 | mkdir -p /host/etc 83 | touch /host/etc/group 84 | nsenter --target 1 --mount -- \ 85 | mount --bind --read-only /etc/group "${container_root_on_host}/host/etc/group" 86 | 87 | # Same for /etc/localtime 88 | mkdir -p /host/etc 89 | touch /host/etc/localtime 90 | nsenter --target 1 --mount -- \ 91 | mount --bind --read-only /etc/localtime "${container_root_on_host}/host/etc/localtime" 92 | 93 | # Same for /etc/os-release 94 | mkdir -p /host/etc 95 | touch /host/etc/os-release 96 | nsenter --target 1 --mount -- \ 97 | mount --bind --read-only /etc/os-release "${container_root_on_host}/host/etc/os-release" 98 | 99 | set +x 100 | 101 | # Restart this container 102 | echo "Restarting this container so that the new mounts take effect..." >&2 103 | curl --fail-with-body --silent --show-error --unix-socket "${docker_sock}" -X POST "http://localhost/containers/${container_id}/restart" 104 | exit 143 105 | fi 106 | 107 | if [[ ! -d /config/netdata && -d /homeassistant/netdata ]]; then 108 | echo "Migrating Netdata configuration files out of Home Assistant config directory..." >&2 109 | mv -fv /homeassistant/netdata /config/ 110 | fi 111 | 112 | # https://github.com/home-assistant/supervisor/issues/3223 113 | echo "Cleaning up old Netdata images if any..." >&2 114 | curl --fail-with-body --silent --show-error --unix-socket "${docker_sock}" http://localhost/images/json | 115 | jq --raw-output '.[] | select(.RepoTags != null) | select(.RepoTags[] | test("netdata/netdata|ghcr.io/netdata/netdata")) | .Id' | 116 | xargs -r -I {} -t -- curl --silent --show-error --unix-socket "${docker_sock}" -X DELETE "http://localhost/images/{}" 117 | 118 | echo "Setting up Netdata directories..." >&2 119 | set -x 120 | mkdir -p /config/netdata /etc/netdata 121 | mount --bind /config/netdata /etc/netdata 122 | 123 | mkdir -p /data/netdata-cache /var/cache/netdata 124 | mount --bind /data/netdata-cache /var/cache/netdata 125 | 126 | mkdir -p /data/netdata-lib /var/lib/netdata 127 | mount --bind /data/netdata-lib /var/lib/netdata 128 | set +x 129 | 130 | echo "Handling Netdata add-on configuration..." >&2 131 | get_config hostname 132 | hostname "${hostname:?}" 133 | 134 | get_config netdata_claim_url 135 | if [[ -n "${netdata_claim_url}" ]]; then 136 | export NETDATA_CLAIM_URL="${netdata_claim_url}" 137 | fi 138 | 139 | get_config netdata_claim_token 140 | if [[ -n "${netdata_claim_token}" ]]; then 141 | export NETDATA_CLAIM_TOKEN="${netdata_claim_token}" 142 | fi 143 | 144 | get_config netdata_claim_rooms 145 | if [[ -n "${netdata_claim_rooms}" ]]; then 146 | export NETDATA_CLAIM_ROOMS="${netdata_claim_rooms}" 147 | fi 148 | 149 | get_config netdata_extra_deb_packages 150 | if [[ -n "${netdata_extra_deb_packages}" ]]; then 151 | export NETDATA_EXTRA_DEB_PACKAGES="${netdata_extra_deb_packages}" 152 | fi 153 | 154 | echo "Starting Netdata..." >&2 155 | exec /usr/sbin/run.sh 156 | --------------------------------------------------------------------------------