This repository has been archived by the owner on Feb 2, 2025. It is now read-only.
forked from CDCgov/openshift-fluentd-forwarder
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrun.sh
72 lines (60 loc) · 2.42 KB
/
run.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
#!/bin/bash
# set up user id into passwd wrapper
export USER_ID=$(id -u)
export GROUP_ID=$(id -g)
cat passwd.template | envsubst > /tmp/passwd
export LD_PRELOAD=/usr/lib64/libnss_wrapper.so
export NSS_WRAPPER_PASSWD=/tmp/passwd
export NSS_WRAPPER_GROUP=/etc/group
USER_NAME=$(id -un)
# show that alternate user IDs are being honored
echo "Running fluentd as user ${USER_NAME} (${USER_ID})"
# copy openshift configmap templte if avaiable, otherwise use built-in template
if [ -f /tmp/fluentd-config/fluentd.conf ]; then
echo "Using OpenShift ConfigMap configuration"
cat /tmp/fluentd-config/fluentd.conf | envsubst > /etc/fluent/fluentd.conf
else
echo "Using Docker image configuration"
cat ~/fluentd.conf.template | envsubst > /etc/fluent/fluentd.conf
fi
ADDITIONAL_OPTS=""
# set additional options if TARGET_TYPE is splunk_ex
if [ "splunk_ex" == "${TARGET_TYPE}" ]; then
ADDITIONAL_OPTS="output_format json"
fi
export ADDITIONAL_OPTS
# set base args to point to fluentd.conf
fluentdargs="-c /etc/fluent/fluentd.conf"
# if verbose then set output to be verbose and print configuration before it is loaded
if [[ $VERBOSE ]]; then
echo "Using Raw Configuration: "
cat /etc/fluent/fluentd.conf
set -ex
fluentdargs="-vv ${fluentdargs}"
else
set -e
fi
# set up IPADDR for fluentd - from OpenShift/Origin logging-fluentd
IPADDR4=`/usr/sbin/ip -4 addr show dev eth0 | grep inet | sed -e "s/[ \t]*inet \([0-9.]*\).*/\1/"`
IPADDR6=`/usr/sbin/ip -6 addr show dev eth0 | grep inet6 | sed "s/[ \t]*inet6 \([a-f0-9:]*\).*/\1/"`
export IPADDR4 IPADDR6
# set up resource limits for fluentd - from OpenShift/Origin logging-fluentd
BUFFER_SIZE_LIMIT=${BUFFER_SIZE_LIMIT:-1048576}
FLUENTD_CPU_LIMIT=${FLUENTD_CPU_LIMIT:-100m}
FLUENTD_MEMORY_LIMIT=${FLUENTD_MEMORY_LIMIT:-512Mi}
MEMORY_LIMIT=`echo $FLUENTD_MEMORY_LIMIT | sed -e "s/[Kk]/*1024/g;s/[Mm]/*1024*1024/g;s/[Gg]/*1024*1024*1024/g;s/i//g" | bc`
BUFFER_SIZE_LIMIT=`echo $BUFFER_SIZE_LIMIT | sed -e "s/[Kk]/*1024/g;s/[Mm]/*1024*1024/g;s/[Gg]/*1024*1024*1024/g;s/i//g" | bc`
if [ $BUFFER_SIZE_LIMIT -eq 0 ]; then
BUFFER_SIZE_LIMIT=1048576
fi
BUFFER_QUEUE_LIMIT=`expr $MEMORY_LIMIT / $BUFFER_SIZE_LIMIT`
if [ $BUFFER_QUEUE_LIMIT -eq 0 ]; then
BUFFER_QUEUE_LIMIT=1024
fi
export BUFFER_QUEUE_LIMIT BUFFER_SIZE_LIMIT
# launch fluentd - from OpenShift/Origin logging-fluentd
if [[ $DEBUG ]] ; then
exec fluentd $fluentdargs > /var/log/fluentd.log 2>&1
else
exec fluentd $fluentdargs
fi