...

Text file src/edge-infra.dev/hack/observability/fluent-bit/fluentbit_install.sh

Documentation: edge-infra.dev/hack/observability/fluent-bit

     1#!/usr/bin/env bash
     2
     3# Script to install fluent-bit on ubuntu based off of instructions from
     4# https://docs.fluentbit.io/manual/installation/linux/ubuntu
     5# The binary is td-agent-bit and will be in /opt/td-agent-bit/bin/
     6
     7# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
     8set -o errexit   # exit script if a command fails
     9set -o nounset   # exit script if a varialbe is undeclared
    10set -o pipefail  # do not hide errors within pipes
    11
    12[[ $(id -u) -ne 0 ]] && echo "This script must run as root" && exit 1
    13
    14os_type_error="Error: This script is only supported on ubuntu focal, bionic or xenial"
    15fb_url="https://packages.fluentbit.io"
    16fb_bin="td-agent-bit"
    17fb_dir="/etc/td-agent-bit"
    18fb_config="./td-agent-bit.conf"
    19fb_parsers="./parsers.conf"
    20fb_secret="./creds.json"
    21if [[ ! -f "${fb_config}" || ! -f "${fb_parsers}" || ! -f "${fb_secret}" ]]; then
    22    echo "required files are missing: ${fb_config} ${fb_parsers} ${fb_secret}"
    23    exit 1
    24fi
    25
    26# source the env variables which tells us which version of ubnutu we're on(focal/bionic/xenial)
    27if [[ -r /etc/os-release ]]; then
    28    # shellcheck disable=SC1091
    29    . /etc/os-release
    30    case "${UBUNTU_CODENAME}" in
    31    "focal" | "bionic" | "xenial")
    32        ;;
    33    *)
    34        echo "${os_type_error}. Found version ${UBUNTU_CODENAME}"
    35        exit 1
    36    ;;
    37    esac
    38else
    39    echo "${os_type_error}"
    40    exit 1
    41fi
    42
    43# add the fluentbit gpg key so we can apt-get the signed td-agent-bit package
    44if ! wget -qO - "${fb_url}"/fluentbit.key | apt-key add - ; then
    45    echo "There was a problem adding fluentbit.key"
    46    exit 1
    47fi
    48
    49sources_file="/etc/apt/sources.list"
    50sources_string="deb ${fb_url}/ubuntu/${UBUNTU_CODENAME} ${UBUNTU_CODENAME} main"
    51echo "checking ${sources_file} for ${sources_string}"
    52if ! grep -q "${sources_string}" "${sources_file}"; then
    53    echo "Updating ${sources_file} with ${sources_string}"
    54    echo "${sources_string}" >> "${sources_file}"
    55fi
    56
    57apt-get update -y
    58
    59echo "checking if we can download ${fb_bin} from ${fb_url}"
    60apt-get -qq --dry-run install "${fb_bin}"
    61# an apt-get error here could indicate an expired root certificate
    62# https://docs.fluentbit.io/manual/installation/linux/ubuntu#certificate-issue
    63if [ $? == 100 ]; then
    64    apt-get install ca-certificates -y
    65fi
    66
    67echo "installing ${fb_bin}"
    68apt-get install "${fb_bin}" -y
    69
    70echo "copying fluent-bit configs to ${fb_dir}"
    71cp "${fb_config}" "${fb_parsers}" "${fb_secret}" "${fb_dir}"
    72
    73echo "staring the ${fb_bin} service"
    74service "${fb_bin}" start
    75service "${fb_bin}" status

View as plain text