forked from logdna/logdna-agent-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
journald_dispatch.sh
executable file
·56 lines (42 loc) · 1.5 KB
/
journald_dispatch.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
#!/usr/bin/env sh
curpath=$(dirname "$0")
image="logdna-agent-journald:latest"
# shellcheck disable=SC2317
_term() {
if [ -z "$child" ]; then
status=$?
else
docker kill "$child"
status=$(docker inspect "$child" --format='{{.State.ExitCode}}')
docker rm "$child"
fi
docker rmi "$image"
exit "$status"
}
# shellcheck source=/dev/null
. "$curpath/lib.sh"
docker build -t "$image" --build-arg "UID=$(id -u)" --build-arg "BUILD_IMAGE=$BUILD_IMAGE" --build-arg "ARCH=$ARCH" -f "$curpath/journald/Dockerfile" "$curpath/.."
trap _term TERM
trap _term INT
journald_args="--tmpfs /tmp --tmpfs /run --tmpfs /run/lock"
# Handle cgroups v2 and v1
if [ -f "/sys/fs/cgroup/cgroup.controllers" ]; then # the kernel has cgroup v2 enabled
journald_args="$journald_args --privileged --cap-add SYS_ADMIN --security-opt seccomp=unconfined --cgroup-parent=docker.slice --cgroupns private"
else
journald_args="$journald_args -v /sys/fs/cgroup:/sys/fs/cgroup:ro"
fi
extra_args="$(get_volume_mounts "$1" "$image") $(get_sccache_args) $journald_args"
# shellcheck disable=SC2086,SC2317
child=$(docker run -d -w "$1" $extra_args -v "$2" $3 "$image")
if [ "$HOST_MACHINE" = "Mac" ]; then
docker exec "$child" /bin/sh -c "$4"
elif [ "$HOST_MACHINE" = "Linux" ]; then
# shellcheck disable=SC2154
docker exec -u "$(id -u)":"$(id -g)" "$child" /bin/sh -c "$start_sccache; $4"
fi
status=$?
# Clean up the container
docker kill "$child" > /dev/null
docker rm "$child" > /dev/null
docker rmi "$image" > /dev/null
exit "$status"