run.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env bash
  2. #
  3. # Entry point script for netdata
  4. #
  5. # Copyright: 2018 and later Netdata Inc.
  6. # SPDX-License-Identifier: GPL-3.0-or-later
  7. #
  8. # Author : Pavlos Emm. Katsoulakis <paul@netdata.cloud>
  9. # Author : Austin S. Hemmelgarn <austin@netdata.cloud>
  10. set -e
  11. if [ ! -w / ] && [ "${EUID}" -eq 0 ]; then
  12. echo >&2 "WARNING: This Docker host appears to not properly support newer stat system calls. This is known to cause issues with Netdata (most notably, nodes running on such hosts **cannot be claimed**)."
  13. echo >&2 "WARNING: For more information, see https://learn.netdata.cloud/docs/agent/claim#known-issues-on-older-hosts-with-seccomp-enabled"
  14. fi
  15. if [ ! "${DISABLE_TELEMETRY:-0}" -eq 0 ] ||
  16. [ -n "$DISABLE_TELEMETRY" ] ||
  17. [ ! "${DO_NOT_TRACK:-0}" -eq 0 ] ||
  18. [ -n "$DO_NOT_TRACK" ]; then
  19. touch /etc/netdata/.opt-out-from-anonymous-statistics
  20. fi
  21. BALENA_PGID=$(stat -c %g /var/run/balena.sock 2>/dev/null || true)
  22. DOCKER_PGID=$(stat -c %g /var/run/docker.sock 2>/dev/null || true)
  23. re='^[0-9]+$'
  24. if [[ $BALENA_PGID =~ $re ]]; then
  25. echo "Netdata detected balena-engine.sock"
  26. DOCKER_HOST='/var/run/balena-engine.sock'
  27. PGID="$BALENA_PGID"
  28. elif [[ $DOCKER_PGID =~ $re ]]; then
  29. echo "Netdata detected docker.sock"
  30. DOCKER_HOST="/var/run/docker.sock"
  31. PGID="$DOCKER_PGID"
  32. fi
  33. export PGID
  34. export DOCKER_HOST
  35. if [ -n "${PGID}" ]; then
  36. echo "Creating docker group ${PGID}"
  37. addgroup -g "${PGID}" "docker" || echo >&2 "Could not add group docker with ID ${PGID}, its already there probably"
  38. echo "Assign netdata user to docker group ${PGID}"
  39. usermod -a -G "${PGID}" "${DOCKER_USR}" || echo >&2 "Could not add netdata user to group docker with ID ${PGID}"
  40. fi
  41. if mountpoint -q /etc/netdata && [ -z "$(ls -A /etc/netdata)" ]; then
  42. echo "Copying stock configuration to /etc/netdata"
  43. cp -a /etc/netdata.stock/. /etc/netdata
  44. fi
  45. if [ -n "${NETDATA_CLAIM_URL}" ] && [ -n "${NETDATA_CLAIM_TOKEN}" ] && [ ! -f /var/lib/netdata/cloud.d/claimed_id ]; then
  46. # shellcheck disable=SC2086
  47. /usr/sbin/netdata-claim.sh -token="${NETDATA_CLAIM_TOKEN}" \
  48. -url="${NETDATA_CLAIM_URL}" \
  49. ${NETDATA_CLAIM_ROOMS:+-rooms="${NETDATA_CLAIM_ROOMS}"} \
  50. ${NETDATA_CLAIM_PROXY:+-proxy="${NETDATA_CLAIM_PROXY}"} \
  51. ${NETDATA_EXTRA_CLAIM_OPTS} \
  52. -daemon-not-running
  53. fi
  54. exec /usr/sbin/netdata -u "${DOCKER_USR}" -D -s /host -p "${NETDATA_LISTENER_PORT}" "$@"