Skip to content

Commit ec43b8b

Browse files
authored
Merge pull request #718 from Paraphraser/20230624-telegraf-master
2023-06-24 Telegraf - master branch - PR 1 of 2
2 parents 8dc3437 + bbc510e commit ec43b8b

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

.templates/telegraf/Dockerfile

100644100755
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ RUN apt update && apt install -y rsync
66

77
# where IOTstack template files are stored
88
ENV IOTSTACK_DEFAULTS_DIR="iotstack_defaults"
9+
ENV BASELINE_CONFIG=/${IOTSTACK_DEFAULTS_DIR}/telegraf-reference.conf
10+
ENV IOTSTACK_CONFIG=/${IOTSTACK_DEFAULTS_DIR}/telegraf.conf
11+
ENV IOTSTACK_ENTRY_POINT="entrypoint.sh"
12+
ENV BASELINE_ENTRY_POINT="entrypoint-reference.sh"
913

1014
# copy template files to image
1115
COPY ${IOTSTACK_DEFAULTS_DIR} /${IOTSTACK_DEFAULTS_DIR}
@@ -14,24 +18,25 @@ COPY ${IOTSTACK_DEFAULTS_DIR} /${IOTSTACK_DEFAULTS_DIR}
1418
# a baseline reference for the user, and make it read-only.
1519
# 2. strip comment lines and blank lines from the baseline reference to
1620
# use as the starting point for the IOTstack default configuration.
17-
# 3. edit the IOTstack default configuration to insert an appropriate
18-
# URL for influxdb running in another container in the same stack.
19-
ENV BASELINE_CONFIG=/${IOTSTACK_DEFAULTS_DIR}/telegraf-reference.conf
20-
ENV IOTSTACK_CONFIG=/${IOTSTACK_DEFAULTS_DIR}/telegraf.conf
21+
# 3. append auto-inclusions which, among other things, sets up the
22+
# the appropriate URL for influxdb running in another container in
23+
# the same stack.
2124
RUN cp /etc/telegraf/telegraf.conf ${BASELINE_CONFIG} && \
2225
cat /${IOTSTACK_DEFAULTS_DIR}/auto_include/*.conf >> ${BASELINE_CONFIG} && \
2326
rm -r /${IOTSTACK_DEFAULTS_DIR}/auto_include && \
2427
chmod 444 ${BASELINE_CONFIG} && \
25-
grep -v -e "^[ ]*#" -e "^[ ]*$" ${BASELINE_CONFIG} >${IOTSTACK_CONFIG} && \
26-
sed -i '/^\[\[outputs.influxdb\]\]/a\ \ urls = ["http://influxdb:8086"]' ${IOTSTACK_CONFIG}
27-
ENV BASELINE_CONFIG=
28-
ENV IOTSTACK_CONFIG=
28+
grep -v -e "^[ ]*#" -e "^[ ]*$" ${BASELINE_CONFIG} >${IOTSTACK_CONFIG}
2929

3030
# replace the docker entry-point script with a self-repairing version
31-
ENV IOTSTACK_ENTRY_POINT="entrypoint.sh"
31+
RUN cp /${IOTSTACK_ENTRY_POINT} /${BASELINE_ENTRY_POINT}
3232
COPY ${IOTSTACK_ENTRY_POINT} /${IOTSTACK_ENTRY_POINT}
3333
RUN chmod 755 /${IOTSTACK_ENTRY_POINT}
34+
35+
# undefine variables not needed at runtime
36+
ENV BASELINE_CONFIG=
37+
ENV IOTSTACK_CONFIG=
3438
ENV IOTSTACK_ENTRY_POINT=
39+
ENV BASELINE_ENTRY_POINT=
3540

3641
# IOTstack declares this path for persistent storage
3742
VOLUME ["/etc/telegraf"]

.templates/telegraf/entrypoint.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,28 @@ fi
99
U="$(id -u)"
1010
T="/etc/telegraf"
1111
if [ "$U" = '0' -a -d "$T" ]; then
12+
echo "Performing IOTstack self repair"
1213
rsync -arp --ignore-existing /${IOTSTACK_DEFAULTS_DIR}/ "$T"
1314
chown -R "$U:$U" "$T"
1415
fi
1516

16-
exec "$@"
17+
if [ $EUID -eq 0 ]; then
18+
19+
# Allow telegraf to send ICMP packets and bind to privliged ports
20+
setcap cap_net_raw,cap_net_bind_service+ep /usr/bin/telegraf || echo "Failed to set additional capabilities on /usr/bin/telegraf"
1721

22+
# note: at this point, the default version of this file runs:
23+
#
24+
# exec setpriv --reuid telegraf --init-groups "$@"
25+
#
26+
# Inside the container, user "telegraf" is userID 999, which
27+
# isn't a member of the "docker" group outside container-space
28+
# so the practical effect of downgrading privileges in this
29+
# way is to deny access to /var/run/docker.sock, and then you
30+
# get a mess. It's not clear whether the setcap is necessary
31+
# on a Raspberry Pi but it has been left in place in case it
32+
# turns out to be useful in other Docker environments.
1833

34+
fi
35+
36+
exec "$@"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[outputs.influxdb]]
2+
urls = ["http://influxdb:8086"]
3+

0 commit comments

Comments
 (0)