diff --git a/recipes-core/images/cvm-initramfs.bbappend b/recipes-core/images/cvm-initramfs.bbappend index b89abb0..4ce4025 100644 --- a/recipes-core/images/cvm-initramfs.bbappend +++ b/recipes-core/images/cvm-initramfs.bbappend @@ -1 +1 @@ -PACKAGE_INSTALL:append = "" +PACKAGE_INSTALL:append = " fluent-bit prometheus node-exporter process-exporter cloudwatch-agent" diff --git a/recipes-tools/cloudwatch-agent/cloudwatch-agent.bb b/recipes-tools/cloudwatch-agent/cloudwatch-agent.bb new file mode 100644 index 0000000..2bf1554 --- /dev/null +++ b/recipes-tools/cloudwatch-agent/cloudwatch-agent.bb @@ -0,0 +1,83 @@ +SUMMARY = "AWS CloudWatch Agent" +DESCRIPTION = "The CloudWatch Agent enables you to collect metrics and logs from Amazon EC2 instances and on-premises servers." +HOMEPAGE = "https://github.com/aws/amazon-cloudwatch-agent" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://src/${GO_WORKDIR}/LICENSE;md5=4dde6168ca1ce801034ffe20cabf2b37" + +DEPENDS = "go-native" +inherit go-mod useradd + +PV = "1.300043.0" +SRCREV = "v1.300043.0" + +SRC_URI = "git://github.com/aws/amazon-cloudwatch-agent.git;protocol=https;nobranch=1 \ + file://cloudwatch-agent.init \ + file://cloudwatch-agent.json" + +S = "${WORKDIR}/git" + +GO_LINKSHARED = "" +do_compile[network] = "1" + +USERADD_PACKAGES = "${PN}" +GROUPADD_PARAM:${PN} = "-r cwagent" +USERADD_PARAM:${PN} = "-r -g cwagent -d /var/lib/cwagent -s /sbin/nologin -c 'CloudWatch Agent' cwagent" + +# reproducible builds +INHIBIT_PACKAGE_DEBUG_SPLIT = '1' +INHIBIT_PACKAGE_STRIP = '1' + +# Set Go import path +GO_IMPORT = "github.com/aws/amazon-cloudwatch-agent" + +do_compile() { + bbwarn "Starting compile task" + cd ${S} + bbwarn "Current directory: $(pwd)" + bbwarn "Directory contents: $(ls -la)" + + # Set GOPATH to include the source directory + export GOPATH="${B}/gopath" + mkdir -p ${GOPATH}/src/$(dirname ${GO_IMPORT}) + ln -sf ${S} ${GOPATH}/src/${GO_IMPORT} + export GO111MODULE=on + cd ${GOPATH}/src/${GO_IMPORT} + bbwarn "Compiling in directory: $(pwd)" + bbwarn "Directory contents: $(ls -la)" + oe_runmake release +} + +do_install() { + install -d ${D}${bindir} + install -m 0755 ${B}/gopath/src/${GO_IMPORT}/build/bin/linux/amd64/amazon-cloudwatch-agent ${D}${bindir}/amazon-cloudwatch-agent + install -m 0755 ${B}/gopath/src/${GO_IMPORT}/build/bin/linux/amd64/amazon-cloudwatch-agent-ctl ${D}${bindir}/amazon-cloudwatch-agent-ctl + install -m 0755 ${B}/gopath/src/${GO_IMPORT}/build/bin/linux/amd64/start-amazon-cloudwatch-agent ${D}${bindir}/start-amazon-cloudwatch-agent + + install -d ${D}${sysconfdir}/amazon/amazon-cloudwatch-agent + install -m 0644 ${WORKDIR}/cloudwatch-agent.json ${D}${sysconfdir}/amazon/amazon-cloudwatch-agent/ + + install -d ${D}${sysconfdir}/init.d + install -m 0755 ${WORKDIR}/cloudwatch-agent.init ${D}${sysconfdir}/init.d/cloudwatch-agent + + # Create directory for CloudWatch Agent data + install -d ${D}/var/lib/cwagent + chown cwagent:cwagent ${D}/var/lib/cwagent + + # Set correct ownership for config directory + chown -R cwagent:cwagent ${D}${sysconfdir}/amazon/amazon-cloudwatch-agent +} + +pkg_postinst_ontarget:${PN}() { + # Ensure the log file can be created by the cwagent user + touch /tmp/amazon-cloudwatch-agent.log + chown cwagent:cwagent /tmp/amazon-cloudwatch-agent.log +} + +inherit update-rc.d + +INITSCRIPT_NAME = "cloudwatch-agent" +INITSCRIPT_PARAMS = "defaults 95 15" + +FILES:${PN} += "${sysconfdir}/amazon /var/lib/cwagent" + +RDEPENDS:${PN} += "openssl" diff --git a/recipes-tools/cloudwatch-agent/files/cloudwatch-agent.init b/recipes-tools/cloudwatch-agent/files/cloudwatch-agent.init new file mode 100644 index 0000000..9808cdd --- /dev/null +++ b/recipes-tools/cloudwatch-agent/files/cloudwatch-agent.init @@ -0,0 +1,57 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: cloudwatch-agent +# Required-Start: $network $remote_fs $syslog +# Required-Stop: $network $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: AWS CloudWatch Agent +# Description: AWS CloudWatch Agent for collecting metrics and logs +### END INIT INFO + +# Source function library. +source /etc/init.d/functions + +DAEMON="/usr/bin/amazon-cloudwatch-agent" +NAME="cloudwatch-agent" +USER="cwagent" +GROUP="cwagent" +PIDFILE="/var/run/$NAME.pid" +CONFIG_FILE="/etc/amazon/amazon-cloudwatch-agent/cloudwatch-agent.json" +LOGFILE="/tmp/amazon-cloudwatch-agent.log" + +do_start() { + echo -n "Starting $NAME: " + start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid $USER:$GROUP -- -config $CONFIG_FILE >> $LOGFILE 2>&1 & + echo $! > $PIDFILE + echo "done." +} + +do_stop() { + echo -n "Stopping $NAME: " + start-stop-daemon --stop --quiet --pidfile $PIDFILE + rm -f $PIDFILE + echo "done." +} + +case "$1" in + start) + do_start + ;; + stop) + do_stop + ;; + restart) + do_stop + do_start + ;; + status) + status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + *) + echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/recipes-tools/cloudwatch-agent/files/cloudwatch-agent.json b/recipes-tools/cloudwatch-agent/files/cloudwatch-agent.json new file mode 100644 index 0000000..ac57b1d --- /dev/null +++ b/recipes-tools/cloudwatch-agent/files/cloudwatch-agent.json @@ -0,0 +1,59 @@ +{ + "agent": { + "metrics_collection_interval": 60, + "run_as_user": "cwagent" + }, + "metrics": { + "namespace": "YoctoMetrics", + "metrics_collected": { + "cpu": { + "resources": [ + "*" + ], + "measurement": [ + "usage_active", + "usage_idle", + "usage_system", + "usage_user" + ], + "totalcpu": false + }, + "mem": { + "measurement": [ + "used_percent", + "used", + "total" + ] + }, + "disk": { + "resources": [ + "/" + ], + "measurement": [ + "used_percent", + "used", + "total" + ] + }, + "diskio": { + "resources": [ + "*" + ], + "measurement": [ + "reads", + "writes", + "read_bytes", + "write_bytes", + "io_time" + ] + }, + "netstat": { + "measurement": [ + "tcp_established", + "tcp_time_wait" + ] + } + } + } + } + \ No newline at end of file diff --git a/recipes-tools/fluent-bit/fluent-bit_3.1.6.bb b/recipes-tools/fluent-bit/fluent-bit_3.1.6.bb new file mode 100644 index 0000000..1ee073e --- /dev/null +++ b/recipes-tools/fluent-bit/fluent-bit_3.1.6.bb @@ -0,0 +1,51 @@ +SUMMARY = "Fluent Bit: Fast and Lightweight Log Processor and Forwarder" +DESCRIPTION = "Fluent Bit is a fast Log Processor and Forwarder for Linux, BSD, OSX, and Windows." +HOMEPAGE = "https://fluentbit.io/" +BUGTRACKER = "https://github.com/fluent/fluent-bit/issues" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://LICENSE;md5=2ee41112a44fe7014dce33e26468ba93" +SECTION = "net" + +SRCREV = "v3.1.6" +SRC_URI = "git://github.com/fluent/fluent-bit.git;branch=master;protocol=https" + +PV = "3.1.6" +S = "${WORKDIR}/git" +INSANE_SKIP_${PN}-dev += "dev-elf" + +# Use CMake 'Unix Makefiles' generator +OECMAKE_GENERATOR ?= "Unix Makefiles" + +DEPENDS = "cmake libyaml openssl zlib bison-native flex-native pkgconfig-native" + +inherit cmake + +EXTRA_OECMAKE = " \ + -DGNU_HOST=${HOST_SYS} \ + -DFLB_DEBUG=Off \ + -DFLB_TRACE=Off \ + -DFLB_JEMALLOC=Off \ + -DFLB_TLS=On \ + -DFLB_SHARED_LIB=Off \ + -DFLB_EXAMPLES=Off \ + -DFLB_SQLDB=Off \ + -DFLB_HTTP_SERVER=On \ + -DFLB_RECORD_ACCESSOR=On \ + -DFLB_LUAJIT=Off \ + -DFLB_FILTER_LUA=Off \ + -DTEST_WRGSBASE_RESULT=0 \ +" + +EXTRA_OECMAKE += " --trace" + + +do_install() { + install -d ${D}${bindir} + install -m 0755 ${B}/bin/fluent-bit ${D}${bindir}/fluent-bit + + install -d ${D}${sysconfdir}/fluent-bit/ + cp -r ${S}/conf/* ${D}${sysconfdir}/fluent-bit/ + + install -d ${D}${docdir}/fluent-bit/ + cp -r ${S}/docs/* ${D}${docdir}/fluent-bit/ +} diff --git a/recipes-tools/node-exporter/files/node_exporter.default b/recipes-tools/node-exporter/files/node_exporter.default new file mode 100644 index 0000000..709d1b7 --- /dev/null +++ b/recipes-tools/node-exporter/files/node_exporter.default @@ -0,0 +1,17 @@ +# Default settings for node_exporter + +# Options to pass to node_exporter +ARGS="" + +# User and group to run node_exporter as +USER="node_exporter" +GROUP="node_exporter" + +# Path to the node_exporter binary +DAEMON="/usr/bin/node_exporter" + +# Path to the PID file +PIDFILE="/var/run/node_exporter.pid" + +# Path to the log file +LOGFILE="/tmp/node_exporter.log" diff --git a/recipes-tools/node-exporter/files/node_exporter.init b/recipes-tools/node-exporter/files/node_exporter.init new file mode 100644 index 0000000..46c452b --- /dev/null +++ b/recipes-tools/node-exporter/files/node_exporter.init @@ -0,0 +1,70 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: node_exporter +# Required-Start: $local_fs $network $named $time $syslog +# Required-Stop: $local_fs $network $named $time $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: Prometheus Node Exporter +### END INIT INFO + +# Set default values +DAEMON="/usr/bin/node_exporter" +USER="node_exporter" +GROUP="node_exporter" +PIDFILE="/var/run/node_exporter.pid" +LOGFILE="/tmp/node_exporter.log" +ARGS="" + +# Read configuration variable file if it is present +[ -r /etc/default/node_exporter ] && . /etc/default/node_exporter + +start() { + if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE) 2>/dev/null; then + echo 'Service already running' >&2 + return 1 + fi + echo 'Starting service…' >&2 + start-stop-daemon --start --quiet --background \ + --make-pidfile --pidfile $PIDFILE \ + --chuid $USER:$GROUP \ + --exec $DAEMON -- $ARGS >> $LOGFILE 2>&1 + echo 'Service started' >&2 +} + +stop() { + if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE") 2>/dev/null; then + echo 'Service not running' >&2 + return 1 + fi + echo 'Stopping service…' >&2 + start-stop-daemon --stop --quiet --pidfile $PIDFILE --name node_exporter + rm -f $PIDFILE + echo 'Service stopped' >&2 +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + status) + if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE) 2>/dev/null; then + echo "Service is running" + else + echo "Service is stopped" + fi + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0 diff --git a/recipes-tools/node-exporter/node-exporter.bb b/recipes-tools/node-exporter/node-exporter.bb new file mode 100644 index 0000000..e83fcd4 --- /dev/null +++ b/recipes-tools/node-exporter/node-exporter.bb @@ -0,0 +1,49 @@ +SUMMARY = "Prometheus exporter for hardware and OS metrics" +DESCRIPTION = "Prometheus exporter for hardware and OS metrics exposed by *NIX kernels, written in Go with pluggable metric collectors." +HOMEPAGE = "https://github.com/prometheus/node_exporter" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://LICENSE;md5=86d3f3a95c324c9479bd8986968f4327" + +inherit update-rc.d useradd + +PV = "1.8.2" + +SRC_URI = "https://github.com/prometheus/node_exporter/releases/download/v${PV}/node_exporter-${PV}.linux-amd64.tar.gz \ + file://node_exporter.init \ + file://node_exporter.default" + +SRC_URI[sha256sum] = "6809dd0b3ec45fd6e992c19071d6b5253aed3ead7bf0686885a51d85c6643c66" + +S = "${WORKDIR}/node_exporter-${PV}.linux-amd64" + +USERADD_PACKAGES = "${PN}" +GROUPADD_PARAM:${PN} = "-r node_exporter" +USERADD_PARAM:${PN} = "-r -g node_exporter -d /var/lib/node_exporter -s /sbin/nologin -c 'Node Exporter' node_exporter" + +do_install() { + install -d ${D}${bindir} + install -m 0755 ${S}/node_exporter ${D}${bindir} + + install -d ${D}${sysconfdir}/init.d + install -m 0755 ${WORKDIR}/node_exporter.init ${D}${sysconfdir}/init.d/node_exporter + + install -d ${D}${sysconfdir}/default + install -m 0644 ${WORKDIR}/node_exporter.default ${D}${sysconfdir}/default/node_exporter + + # Create directory for Node Exporter data + install -d ${D}/var/lib/node_exporter + + # Set correct ownership + chown -R node_exporter:node_exporter ${D}/var/lib/node_exporter +} + +pkg_postinst_ontarget:${PN}() { + # Ensure the log file can be created by the node_exporter user + touch /tmp/node_exporter.log + chown node_exporter:node_exporter /tmp/node_exporter.log +} + +INITSCRIPT_NAME = "node_exporter" +INITSCRIPT_PARAMS = "defaults 95 15" + +FILES:${PN} += "${sysconfdir} /var/lib/node_exporter" diff --git a/recipes-tools/process-exporter/files/process-exporter.default b/recipes-tools/process-exporter/files/process-exporter.default new file mode 100644 index 0000000..0f026a0 --- /dev/null +++ b/recipes-tools/process-exporter/files/process-exporter.default @@ -0,0 +1,17 @@ +# Default settings for process-exporter + +# Options to pass to process-exporter +ARGS="-config.path=/etc/process-exporter/process-exporter.yaml" + +# User and group to run process-exporter as +USER="process-exporter" +GROUP="process-exporter" + +# Path to the process-exporter binary +DAEMON="/usr/bin/process-exporter" + +# Path to the PID file +PIDFILE="/var/run/process-exporter.pid" + +# Path to the log file +LOGFILE="/tmp/process-exporter.log" diff --git a/recipes-tools/process-exporter/files/process-exporter.init b/recipes-tools/process-exporter/files/process-exporter.init new file mode 100644 index 0000000..742c9a6 --- /dev/null +++ b/recipes-tools/process-exporter/files/process-exporter.init @@ -0,0 +1,71 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: process-exporter +# Required-Start: $local_fs $network $named $time $syslog +# Required-Stop: $local_fs $network $named $time $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: Prometheus Process Exporter +### END INIT INFO + +# Set default values +DAEMON="/usr/bin/process-exporter" +USER="process-exporter" +GROUP="process-exporter" +PIDFILE="/var/run/process-exporter.pid" +LOGFILE="/tmp/process-exporter.log" +CONFIG="/etc/process-exporter/process-exporter.yaml" +ARGS="-config.path=$CONFIG" + +# Read configuration variable file if it is present +[ -r /etc/default/process-exporter ] && . /etc/default/process-exporter + +start() { + if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE) 2>/dev/null; then + echo 'Service already running' >&2 + return 1 + fi + echo 'Starting service…' >&2 + start-stop-daemon --start --quiet --background \ + --make-pidfile --pidfile $PIDFILE \ + --chuid $USER:$GROUP \ + --exec $DAEMON -- $ARGS >> $LOGFILE 2>&1 + echo 'Service started' >&2 +} + +stop() { + if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE") 2>/dev/null; then + echo 'Service not running' >&2 + return 1 + fi + echo 'Stopping service…' >&2 + start-stop-daemon --stop --quiet --pidfile $PIDFILE --name process-exporter + rm -f $PIDFILE + echo 'Service stopped' >&2 +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + status) + if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE) 2>/dev/null; then + echo "Service is running" + else + echo "Service is stopped" + fi + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0 diff --git a/recipes-tools/process-exporter/files/process-exporter.yaml b/recipes-tools/process-exporter/files/process-exporter.yaml new file mode 100644 index 0000000..b68afb5 --- /dev/null +++ b/recipes-tools/process-exporter/files/process-exporter.yaml @@ -0,0 +1,4 @@ +process_names: + - name: "{{.Comm}}" + cmdline: + - '.+' diff --git a/recipes-tools/process-exporter/process-exporter.bb b/recipes-tools/process-exporter/process-exporter.bb new file mode 100644 index 0000000..86239ed --- /dev/null +++ b/recipes-tools/process-exporter/process-exporter.bb @@ -0,0 +1,57 @@ +SUMMARY = "Process exporter for Prometheus" +DESCRIPTION = "Prometheus exporter that mines /proc to report on selected processes" +HOMEPAGE = "https://github.com/ncabatoff/process-exporter" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://LICENSE;md5=8748f01be17d4b2ce4421ce67a12c479" + +inherit update-rc.d useradd + +PV = "0.8.3" + +SRC_URI = "https://github.com/ncabatoff/process-exporter/releases/download/v${PV}/process-exporter-${PV}.linux-amd64.tar.gz \ + file://process-exporter.init \ + file://process-exporter.default \ + file://process-exporter.yaml" + +SRC_URI[sha256sum] = "249db36771a4e66eaacca0ce31294de200df30eaf59a190c46639b98c5815969" + +S = "${WORKDIR}/process-exporter-${PV}.linux-amd64" + +USERADD_PACKAGES = "${PN}" +GROUPADD_PARAM:${PN} = "-r process-exporter" +USERADD_PARAM:${PN} = "-r -g process-exporter -d /var/lib/process-exporter -s /sbin/nologin -c 'Process Exporter' process-exporter" + +do_install() { + install -d ${D}${bindir} + install -m 0755 ${S}/process-exporter ${D}${bindir} + + install -d ${D}${sysconfdir}/process-exporter + install -m 0644 ${WORKDIR}/process-exporter.yaml ${D}${sysconfdir}/process-exporter/ + + install -d ${D}${sysconfdir}/init.d + install -m 0755 ${WORKDIR}/process-exporter.init ${D}${sysconfdir}/init.d/process-exporter + + install -d ${D}${sysconfdir}/default + install -m 0644 ${WORKDIR}/process-exporter.default ${D}${sysconfdir}/default/process-exporter + + # Create directory for Process Exporter data + install -d ${D}/var/lib/process-exporter + + # Set correct ownership + chown -R process-exporter:process-exporter ${D}/var/lib/process-exporter + chown -R process-exporter:process-exporter ${D}${sysconfdir}/process-exporter +} + +pkg_postinst_ontarget:${PN}() { + # Ensure the log file can be created by the process-exporter user + touch /tmp/process-exporter.log + chown process-exporter:process-exporter /tmp/process-exporter.log +} + +INITSCRIPT_NAME = "process-exporter" +INITSCRIPT_PARAMS = "defaults 95 15" + +FILES:${PN} += "${sysconfdir} /var/lib/process-exporter" + +# Override QA check for already-stripped binaries +INSANE_SKIP:${PN} += "already-stripped" diff --git a/recipes-tools/prometheus/files/prometheus.default b/recipes-tools/prometheus/files/prometheus.default new file mode 100644 index 0000000..76e93f2 --- /dev/null +++ b/recipes-tools/prometheus/files/prometheus.default @@ -0,0 +1,30 @@ +# Default settings for prometheus +# This file is sourced by /etc/init.d/prometheus + +# User and group to run prometheus as +USER="prometheus" +GROUP="prometheus" + +# Path to Prometheus configuration file +CONFIG="/etc/prometheus/prometheus.yml" + +# Path to Prometheus data directory +DATA_DIR="/var/lib/prometheus" + +# Path to Prometheus log file +LOG_FILE="/tmp/prometheus.log" + +# Additional arguments to pass to prometheus +ARGS="--config.file=${CONFIG} \ + --storage.tsdb.path=${DATA_DIR} \ + --web.console.templates=/usr/share/prometheus/consoles \ + --web.console.libraries=/usr/share/prometheus/console_libraries" + +# Uncomment and modify the following line to change the default listening address +#ARGS="${ARGS} --web.listen-address=0.0.0.0:9090" + +# Uncomment and modify the following line to enable remote write +#ARGS="${ARGS} --enable-feature=remote-write-receiver" + +# Uncomment and modify the following line to change retention time (default is 15d) +#ARGS="${ARGS} --storage.tsdb.retention.time=30d" \ No newline at end of file diff --git a/recipes-tools/prometheus/files/prometheus.init b/recipes-tools/prometheus/files/prometheus.init new file mode 100644 index 0000000..7f43152 --- /dev/null +++ b/recipes-tools/prometheus/files/prometheus.init @@ -0,0 +1,75 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: prometheus +# Required-Start: $local_fs $network $named $time $syslog +# Required-Stop: $local_fs $network $named $time $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: Prometheus monitoring system and time series database +### END INIT INFO + +NAME=prometheus +DAEMON=/usr/bin/prometheus +PIDFILE=/var/run/$NAME/$NAME.pid +LOGFILE=/tmp/$NAME.log +DAEMON_ARGS="--config.file=/etc/prometheus/prometheus.yml" +USER=prometheus +GROUP=prometheus + +# Read configuration variable file if it is present +[ -r /etc/default/$NAME ] && . /etc/default/$NAME + +start() { + echo "Starting $NAME" + mkdir -p /var/run/$NAME + chown $USER:$GROUP /var/run/$NAME + touch $LOGFILE + chown $USER:$GROUP $LOGFILE + start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --chuid $USER:$GROUP --exec $DAEMON -- $DAEMON_ARGS > $LOGFILE 2>&1 + echo "$NAME started" +} + +stop() { + echo "Stopping $NAME" + start-stop-daemon --stop --quiet --pidfile $PIDFILE + rm -f $PIDFILE + echo "$NAME stopped" +} + +status() { + if [ -f $PIDFILE ]; then + PID=$(cat $PIDFILE) + if kill -0 $PID > /dev/null 2>&1; then + echo "$NAME is running (PID: $PID)" + return 0 + else + echo "$NAME is not running (stale PID file)" + return 1 + fi + else + echo "$NAME is not running" + return 3 + fi +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + status) + status + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0 diff --git a/recipes-tools/prometheus/prometheus.bb b/recipes-tools/prometheus/prometheus.bb new file mode 100644 index 0000000..923b248 --- /dev/null +++ b/recipes-tools/prometheus/prometheus.bb @@ -0,0 +1,58 @@ +SUMMARY = "Prometheus monitoring system and time series database" +DESCRIPTION = "Prometheus is an open-source systems monitoring and alerting toolkit" +HOMEPAGE = "https://prometheus.io/" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://LICENSE;md5=86d3f3a95c324c9479bd8986968f4327" + +inherit update-rc.d useradd + +PV = "2.54.0" + +SRC_URI = "https://github.com/prometheus/prometheus/releases/download/v${PV}/prometheus-${PV}.linux-amd64.tar.gz \ + file://prometheus.init \ + file://prometheus.default" + +SRC_URI[sha256sum] = "465e1393a0cca9705598f6ffaf96ffa78d0347808ab21386b0c6aaec2cf7aa13" + +S = "${WORKDIR}/prometheus-${PV}.linux-amd64" + +USERADD_PACKAGES = "${PN}" +GROUPADD_PARAM:${PN} = "-r prometheus" +USERADD_PARAM:${PN} = "-r -g prometheus -d /var/lib/prometheus -s /sbin/nologin -c 'Prometheus monitoring system' prometheus" + +do_install() { + install -d ${D}${bindir} + install -m 0755 ${S}/prometheus ${D}${bindir} + install -m 0755 ${S}/promtool ${D}${bindir} + + install -d ${D}${sysconfdir}/prometheus + install -m 0644 ${S}/prometheus.yml ${D}${sysconfdir}/prometheus/ + + install -d ${D}${sysconfdir}/init.d + install -m 0755 ${WORKDIR}/prometheus.init ${D}${sysconfdir}/init.d/prometheus + + install -d ${D}${sysconfdir}/default + install -m 0644 ${WORKDIR}/prometheus.default ${D}${sysconfdir}/default/prometheus + + install -d ${D}${datadir}/prometheus + cp -r ${S}/console_libraries ${D}${datadir}/prometheus/ + cp -r ${S}/consoles ${D}${datadir}/prometheus/ + + # Create directory for Prometheus data + install -d ${D}/var/lib/prometheus + + # Set correct ownership + chown -R prometheus:prometheus ${D}/var/lib/prometheus + chown -R prometheus:prometheus ${D}${sysconfdir}/prometheus +} + +pkg_postinst_ontarget:${PN}() { + # Ensure the log file can be created by the prometheus user + touch /tmp/prometheus.log + chown prometheus:prometheus /tmp/prometheus.log +} + +INITSCRIPT_NAME = "prometheus" +INITSCRIPT_PARAMS = "defaults 85 15" + +FILES:${PN} += "${sysconfdir} ${datadir}/prometheus /var/lib/prometheus"