-
Notifications
You must be signed in to change notification settings - Fork 46
/
entrypoint.sh
executable file
·117 lines (101 loc) · 4.16 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
# shellcheck disable=SC1091
[[ ! -e ./debug-info.conf ]] || source ./debug-info.conf
if [[ "${EBPF_NET_DEBUG_MODE}" == true ]]; then
echo "===================== /etc/os-release ====================="
[[ ! -e /etc/os-release ]] || cat /etc/os-release
echo "========================= uname -a ========================"
uname -a
echo "======================= environment ======================="
env | sort
echo "==========================================================="
fi
install_dir=${EBPF_NET_INSTALL_DIR:-/srv}
data_dir=${EBPF_NET_DATA_DIR:-/var/run/ebpf_net}
dump_dir="${data_dir}/dump"
mkdir -p "${data_dir}" "${dump_dir}"
kernel_headers_info_path="${data_dir}/kernel_headers.cfg"
kernel_headers_log_path="${data_dir}/kernel_headers.log"
echo "resolving kernel headers..."
if "${install_dir}/kernel_headers.sh" "${kernel_headers_info_path}" \
> "${kernel_headers_log_path}" 2>&1
then
# shellcheck disable=SC1090
. "${kernel_headers_info_path}"
else
entrypoint_error="unknown"
fi
# cleanup kprobes previously created by the kernel collector
mount -t debugfs none /sys/kernel/debug
if [[ -f /sys/kernel/debug/tracing/kprobe_events ]]; then
echo "cleaning up stale kprobes..."
tmpfile="${data_dir}/ebpf_net_kprobes"
grep "ebpf_net_" /sys/kernel/debug/tracing/kprobe_events \
| cut -d: -f2 | sed -e 's/^/-:/' > "$tmpfile"
cat "$tmpfile" >> /sys/kernel/debug/tracing/kprobe_events
rm -f "$tmpfile"
fi
cmd_args=( \
--host-distro "${host_distro:-unknown}"
--kernel-headers-source "${kernel_headers_source:-unknown}"
)
# Errors that take place before the agent is run will be reported through the
# command line flag `entrypoint_error`.
# Logging and troubleshooting will be handled by the agent itself.
if [[ -n "${entrypoint_error}" ]]; then
cmd_args+=(--entrypoint-error "${entrypoint_error}")
if [[ "${entrypoint_error}" != "kernel_headers_fetch_refuse" ]] && [[ -e "${kernel_headers_log_path}" ]]; then
echo "--- BEGIN log from kernel headers resolution with error '${entrypoint_error}': -------------"
cat "${kernel_headers_log_path}" || true
echo "--- END log from kernel headers resolution with error '${entrypoint_error}': -------------"
fi
fi
echo "launching kernel collector..."
# on Debug (non-production) images, devs can run in local mode by setting
# `EBPF_NET_RUN_LOCAL` to non-empty.
if [[ -n "${EBPF_NET_RUN_LOCAL}" ]]; then
# shellcheck disable=SC1091
source /srv/local.sh
cmd_args+=("${local_cmd_args[@]}")
fi
# to run the collector under gdb, set `EBPF_NET_RUN_UNDER_GDB` to the flavor of gdb
# you want (e.g.: `cgdb` or `gdb`) - this is intended for development purposes
if [[ -n "${EBPF_NET_RUN_UNDER_GDB}" ]]; then
apt-get update -y
apt-get install -y --no-install-recommends "${EBPF_NET_RUN_UNDER_GDB}"
if [[ "${#EBPF_NET_GDB_COMMANDS[@]}" -lt 1 ]]; then
# default behavior is to run the agent, print a stack trace after it exits
# and exit gdb without confirmation
EBPF_NET_GDB_COMMANDS=( \
'set pagination off'
'handle SIGPIPE nostop pass'
'handle SIGUSR1 nostop pass'
'handle SIGUSR2 nostop pass'
run
bt
'server q'
)
fi
GDB_ARGS=()
for gdb_cmd in "${EBPF_NET_GDB_COMMANDS[@]}"; do
GDB_ARGS+=(-ex "${gdb_cmd}")
done
(set -x; exec "${EBPF_NET_RUN_UNDER_GDB}" -q "${GDB_ARGS[@]}" \
--args "${install_dir}/kernel-collector" "${cmd_args[@]}" "$@" \
)
elif [[ -n "${EBPF_NET_RUN_UNDER_VALGRIND}" ]]; then
# to run the collector under valgrind, set `EBPF_NET_RUN_UNDER_VALGRIND` to the options to pass to valgrind,
# including at minimum the tool you want, for example:
# "--tool=memcheck", or
# "--tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes", or
# "--tool=massif --stacks=yes"
# note: to get full symbols from valgrind also build the kernel-collector in debug mode
apt update -y
apt install -y valgrind
# shellcheck disable=SC2086
(set -x; exec /usr/bin/valgrind ${EBPF_NET_RUN_UNDER_VALGRIND} "${install_dir}/kernel-collector" "${cmd_args[@]}" "$@")
else
(set -x; exec "${install_dir}/kernel-collector" "${cmd_args[@]}" "$@")
fi