#!/sbin/openrc-run # Copyright 1999-2022 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 METRICBEAT_USER="${METRICBEAT_USER:-root}" METRICBEAT_GROUP="${METRICBEAT_GROUP:-root}" METRICBEAT_CONFIG="${METRICBEAT_CONFIG:-/etc/metricbeat/metricbeat.yml}" METRICBEAT_DATADIR="${METRICBEAT_DATADIR:-/var/lib/metricbeat}" METRICBEAT_LOGDIR="${METRICBEAT_LOGDIR:-/var/log/metricbeat}" METRICBEAT_OPTS="${METRICBEAT_OPTS:-}" command="/usr/bin/metricbeat" command_args="-c ${METRICBEAT_CONFIG} ${METRICBEAT_OPTS} -path.config $(dirname $METRICBEAT_CONFIG) \ -path.data ${METRICBEAT_DATADIR} -path.home ${METRICBEAT_DATADIR} -path.logs ${METRICBEAT_LOGDIR}" command_background="true" command_user="${METRICBEAT_USER}:${METRICBEAT_GROUP}" extra_commands="checkconfig" pidfile="/run/metricbeat.pid" retry="TERM/5/KILL/5" start_stop_daemon_args="--chdir ${METRICBEAT_DATADIR}" depend() { use net after elasticsearch } checkconfig() { if [ ! -e ${METRICBEAT_CONFIG} ]; then eend "Please create a configuration file at ${METRICBEAT_CONFIG}" return 1 fi ebegin "Checking your configuration" ${command} ${command_args} test config eend $? "Configuration error. Please fix your configuration files." } start_pre() { checkconfig || return 1 checkpath -d -o "${METRICBEAT_USER}":"${METRICBEAT_GROUP}" -m750 "${METRICBEAT_DATADIR}" checkpath -d -o "${METRICBEAT_USER}":"${METRICBEAT_GROUP}" -m750 "${METRICBEAT_LOGDIR}" }