From 030a626826a8c8be8d7c9c204361e6e68fc96b94 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Mon, 11 Nov 2019 22:40:30 +0100 Subject: [PATCH] app-metrics/mysqld_exporter: Add ebuild with systemd service file. Package-Manager: Portage-2.3.76, Repoman-2.3.16 --- app-metrics/mysqld_exporter/ChangeLog | 7 ++ app-metrics/mysqld_exporter/Manifest | 9 +++ .../files/mysqld_exporter-r1.confd | 26 +++++++ .../files/mysqld_exporter-r1.initd | 73 +++++++++++++++++++ .../files/mysqld_exporter.confd | 26 +++++++ .../files/mysqld_exporter.logrotate | 5 ++ .../files/mysqld_exporter.service | 10 +++ app-metrics/mysqld_exporter/metadata.xml | 11 +++ .../mysqld_exporter-0.11.0.ebuild | 73 +++++++++++++++++++ 9 files changed, 240 insertions(+) create mode 100644 app-metrics/mysqld_exporter/ChangeLog create mode 100644 app-metrics/mysqld_exporter/Manifest create mode 100644 app-metrics/mysqld_exporter/files/mysqld_exporter-r1.confd create mode 100644 app-metrics/mysqld_exporter/files/mysqld_exporter-r1.initd create mode 100644 app-metrics/mysqld_exporter/files/mysqld_exporter.confd create mode 100644 app-metrics/mysqld_exporter/files/mysqld_exporter.logrotate create mode 100644 app-metrics/mysqld_exporter/files/mysqld_exporter.service create mode 100644 app-metrics/mysqld_exporter/metadata.xml create mode 100644 app-metrics/mysqld_exporter/mysqld_exporter-0.11.0.ebuild diff --git a/app-metrics/mysqld_exporter/ChangeLog b/app-metrics/mysqld_exporter/ChangeLog new file mode 100644 index 0000000..972c94b --- /dev/null +++ b/app-metrics/mysqld_exporter/ChangeLog @@ -0,0 +1,7 @@ +*mysqld_exporter-0.11.0 (11 Nov 2019) + + 11 Nov 2019; +files/mysqld_exporter-r1.confd, + +files/mysqld_exporter-r1.initd, +files/mysqld_exporter.confd, + +files/mysqld_exporter.logrotate, +files/mysqld_exporter.service, + +metadata.xml, +mysqld_exporter-0.11.0.ebuild: + app-metrics/mysqld_exporter: Add ebuild with systemd service file. diff --git a/app-metrics/mysqld_exporter/Manifest b/app-metrics/mysqld_exporter/Manifest new file mode 100644 index 0000000..aa6b0bc --- /dev/null +++ b/app-metrics/mysqld_exporter/Manifest @@ -0,0 +1,9 @@ +AUX mysqld_exporter-r1.confd 893 BLAKE2B bebec4ba675a5f7bfec52f0c1ad3b824f032258397dc9386892daa4d93ca1f7134c85e92c7662f9bd5b34d86478e2b3be2fc5b4adfb6fa1ece8d901ae530ec3e SHA512 3291e96479ece4f99de2c26e127469349f6197bc2764691fb4bffe5729fc9ce625fa84e2859649f0495260b339afa20edaa7bd2af99e6f161e6e6bbb153eee39 +AUX mysqld_exporter-r1.initd 2050 BLAKE2B f36d0d954e577f939f613887f86952ebf2460237df487b376237045bf1f0fae76ca0c1c7ba6359d2e702a817ff0b581984244c2263019b2f89d6d938e4b329eb SHA512 4b69f492cb240797247549f02f12577146d8df219ff51c92a494f126e0fc2382de4b1d92807669e7f2f385bff38009db0b117fe9c2c88da48e875452e35a404c +AUX mysqld_exporter.confd 891 BLAKE2B 340b8d6b5f3fdc0a52851197cfd94b1d9d20fa3cda349c581a016c6cc7edd53cb7d86b634487551f916fd5c84294add402397cb9bf0fc2efb211b589dd571dd2 SHA512 ed4f949c8f5f88ad54c536342adf90be5d74922b54c383735a957e571aba341057830c7e8cdc0e45b53e439c5297d3ad70ba7bd178f77d10615787ed51bcc03f +AUX mysqld_exporter.logrotate 68 BLAKE2B 04a9a0df5dae2a2afd3374cd6f6fd5d04df7629bc85ed63792ecc9e2b4772668d1f5b1fe4baf14b17c26a495ffa1ed3a7d748719db9a72f427587243505158d1 SHA512 3eb2e6bfa0eae0847c0b1e2e7fd990068cb0ad570d14463c88a8860d70ebc378b2e3bc4141f0a98e95304c972c765ae48dbff726b208ba825fe1f4e58765e462 +AUX mysqld_exporter.service 200 BLAKE2B 1053fe71dd3a1066ad5512f8ad2b40e34411365816b40f9c8f79b49a125099d0dc479c8cafce4ef4a5ca214859100324d04a1d429403dd08c4107e013f221acf SHA512 aaf7d1eb499aea03b435be24c0949f503f69759ce3507ccf08b81136ccde19d7720f42892924a701931a5ce8fdf297bf889725b789a538fed5e2f87568a95e38 +DIST mysqld_exporter-0.11.0.tar.gz 1393809 BLAKE2B ac6b04d2ad24f1c083c411f10bbb6724c2458be357ff60e1950aa624955497432295726e7f739dff03aa1ed8290d852a9511e01893f5a2b293e79b3214270578 SHA512 69f39ecc1b17bfcfd3acdad9d92a70c1daf3f0c9690770fa390a818bd29f43a98bfe4856f22b48e9d2d9945ce98ded0ea54c95010755a85ebc3ebfdc353d0c24 +EBUILD mysqld_exporter-0.11.0.ebuild 1958 BLAKE2B ecced5032743230e246b8813579106a1ba8099ba179261e6322d45a1bc7081c48b2e844c915fc1d6b1bffb9473967aa0821826c9558fdd79ae87043d302c4676 SHA512 5f54025d4e9e6893361eb2c5ae19fc83102ab67187fefe1a310545b2a8e799bea9666d55ff9a8dffa6941a8698f78b2160d908ef5e37495308ab4ce1ac6cbf47 +MISC ChangeLog 359 BLAKE2B fe52cf4b121f0771017562b127a49960ebad5f927776daa2d29b39933c31339f8147b45a30e2b623de534ebf828827d022b2a1405ba903e8b3c583752473af0f SHA512 28b7b9e9df366ce4563a8a6cc635fd1b85b0351f61c7a057f99c9d6d4102ba13aa4e78c1f664ac308b45529948cbe11a74f626970c0f769aadf369c05b43f10d +MISC metadata.xml 339 BLAKE2B cc95303dfddecf9c81e77995bca8719a87cc74b9c3a95142bea4bc13d9fba4767ea7d5bdc56731e45f59a27a66dfd1e7ecb6924c737961ff30cd690c9ab250b5 SHA512 21cf66c2810306d975812118206a29d21f8ae3ed887c41c43fc66603a5901e261fe86d80e04160a7a31eaceec759f128e09b127a7c885fea0a3d06415743d022 diff --git a/app-metrics/mysqld_exporter/files/mysqld_exporter-r1.confd b/app-metrics/mysqld_exporter/files/mysqld_exporter-r1.confd new file mode 100644 index 0000000..2b7f9bf --- /dev/null +++ b/app-metrics/mysqld_exporter/files/mysqld_exporter-r1.confd @@ -0,0 +1,26 @@ +# /etc/conf.d/mysqld_exporter + +# PID file +#EXPORTER_PIDFILE="/run/${RC_SVCNAME}.pid" + +# The termination timeout (start-stop-daemon parameter "retry") ensures +# that the service will be terminated within a given time (60 + 5 seconds +# per default) when you are stopping the service. +#EXPORTER_TERMTIMEOUT="TERM/60/KILL/5" + +# User to run exporter as +#EXPORTER_USER="mysqld_exporter" + +# User group to run exporter as +#EXPORTER_GROUP="mysqld_exporter" + +# You can use this configuration option to pass additional options to the +# start-stop-daemon, see start-stop-daemon(8) for more details. +# Per default we wait 1000ms after we have started the service to ensure +# that the daemon is really up and running. +#EXPORTER_SSDARGS="--wait 1000" + +# Exporter flags +# See `mysqld_exporter --help` for more details +EXPORTER_FLAGS="--log.level=info" +#EXPORTER_FLAGS="${EXPORTER_FLAGS} --yourAdditionalFlag" diff --git a/app-metrics/mysqld_exporter/files/mysqld_exporter-r1.initd b/app-metrics/mysqld_exporter/files/mysqld_exporter-r1.initd new file mode 100644 index 0000000..11a2555 --- /dev/null +++ b/app-metrics/mysqld_exporter/files/mysqld_exporter-r1.initd @@ -0,0 +1,73 @@ +#!/sbin/openrc-run +# Copyright 2016-2019 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +description="Prometheus exporter for MySQL server metrics" + +EXPORTER_FLAGS=${EXPORTER_FLAGS:-""} +EXPORTER_USER=${EXPORTER_USER:-"mysqld_exporter"} +EXPORTER_GROUP=${EXPORTER_GROUP:-"mysqld_exporter"} +EXPORTER_PIDFILE=${EXPORTER_PIDFILE:-"/run/${RC_SVCNAME}.pid"} +EXPORTER_SSDARGS=${EXPORTER_SSDARGS:-"--wait 1000"} +EXPORTER_TERMTIMEOUT=${EXPORTER_TERMTIMEOUT:-"TERM/60/KILL/5"} + +command="/usr/bin/mysqld_exporter" +command_args="${EXPORTER_FLAGS}" +command_background="true" +start_stop_daemon_args="${EXPORTER_SSDARGS}" +start_stop_daemon_args="${start_stop_daemon_args} --user ${EXPORTER_USER}" +start_stop_daemon_args="${start_stop_daemon_args} --group ${EXPORTER_GROUP}" + +# We are forcing log files because upstream is going to remove syslog support :/ +start_stop_daemon_args="${start_stop_daemon_args} --stdout /var/log/mysqld_exporter/${RC_SVCNAME}.log" +start_stop_daemon_args="${start_stop_daemon_args} --stderr /var/log/mysqld_exporter/${RC_SVCNAME}.log" + +getconfig() { + local key="$1" + local value_default="$2" + local value= + + if service_started; then + value="$(service_get_value "${key}")" + fi + + if [ -z "${value}" ]; then + # Value not explicitly set + echo "${value_default}" + else + echo "${value}" + fi + + return 0 +} + +pidfile="$(getconfig pidfile ${EXPORTER_PIDFILE})" +retry="$(getconfig retry ${EXPORTER_TERMTIMEOUT})" + +configtest() { + if test "${command_args#*config\.my-cnf}" = "${command_args}"; then + local _default_config_file="/var/lib/mysqld_exporter/.my.cnf" + if [ ! -s "${_default_config_file}" ]; then + eerror "No MySQL credentials found in \"${_default_config_file}\"!" + eerror "Either create that file and add credentials or specify another file via \"-config.my-cnf\" flag." + return 1 + fi + fi + + return 0 +} + +depend() { + after net + use mysql +} + +start_pre() { + if [ "${RC_CMD}" != "restart" ]; then + configtest || return 1 + fi +} + +start_post() { + service_set_value retry "${EXPORTER_TERMTIMEOUT}" +} diff --git a/app-metrics/mysqld_exporter/files/mysqld_exporter.confd b/app-metrics/mysqld_exporter/files/mysqld_exporter.confd new file mode 100644 index 0000000..249ed7e --- /dev/null +++ b/app-metrics/mysqld_exporter/files/mysqld_exporter.confd @@ -0,0 +1,26 @@ +# /etc/conf.d/mysqld_exporter + +# PID file +#EXPORTER_PIDFILE="/run/${RC_SVCNAME}.pid" + +# The termination timeout (start-stop-daemon parameter "retry") ensures +# that the service will be terminated within a given time (60 + 5 seconds +# per default) when you are stopping the service. +#EXPORTER_TERMTIMEOUT="TERM/60/KILL/5" + +# User to run exporter as +#EXPORTER_USER="mysqld_exporter" + +# User group to run exporter as +#EXPORTER_GROUP="mysqld_exporter" + +# You can use this configuration option to pass additional options to the +# start-stop-daemon, see start-stop-daemon(8) for more details. +# Per default we wait 1000ms after we have started the service to ensure +# that the daemon is really up and running. +#EXPORTER_SSDARGS="--wait 1000" + +# Exporter flags +# See `mysqld_exporter --help` for more details +EXPORTER_FLAGS="-log.level=info" +#EXPORTER_FLAGS="${EXPORTER_FLAGS} -yourAdditionalFlag" diff --git a/app-metrics/mysqld_exporter/files/mysqld_exporter.logrotate b/app-metrics/mysqld_exporter/files/mysqld_exporter.logrotate new file mode 100644 index 0000000..ec360d7 --- /dev/null +++ b/app-metrics/mysqld_exporter/files/mysqld_exporter.logrotate @@ -0,0 +1,5 @@ +/var/log/mysqld_exporter/*.log { + missingok + notifempty + size 30k +} diff --git a/app-metrics/mysqld_exporter/files/mysqld_exporter.service b/app-metrics/mysqld_exporter/files/mysqld_exporter.service new file mode 100644 index 0000000..6a3cb79 --- /dev/null +++ b/app-metrics/mysqld_exporter/files/mysqld_exporter.service @@ -0,0 +1,10 @@ +[Unit] +Description=MySqld Exporter + +[Service] +User=mysqld_exporter +EnvironmentFile=/etc/conf.d/mysqld_exporter +ExecStart=/usr/bin/mysqld_exporter $EXPORTER_FLAGS + +[Install] +WantedBy=multi-user.target diff --git a/app-metrics/mysqld_exporter/metadata.xml b/app-metrics/mysqld_exporter/metadata.xml new file mode 100644 index 0000000..44dc555 --- /dev/null +++ b/app-metrics/mysqld_exporter/metadata.xml @@ -0,0 +1,11 @@ + + + + + manuel@fritteli.ch + Manuel Friedli + + + prometheus/mysqld_exporter + + diff --git a/app-metrics/mysqld_exporter/mysqld_exporter-0.11.0.ebuild b/app-metrics/mysqld_exporter/mysqld_exporter-0.11.0.ebuild new file mode 100644 index 0000000..56b1df4 --- /dev/null +++ b/app-metrics/mysqld_exporter/mysqld_exporter-0.11.0.ebuild @@ -0,0 +1,73 @@ +# Copyright 1999-2019 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI="6" +inherit eapi7-ver user golang-build golang-vcs-snapshot systemd + +EGO_PN="github.com/prometheus/mysqld_exporter" +EGIT_COMMIT="v${PV/_rc/-rc.}" +MYSQLD_EXPORTER_COMMIT="8068006" +ARCHIVE_URI="https://${EGO_PN}/archive/${EGIT_COMMIT}.tar.gz -> ${P}.tar.gz" +KEYWORDS="~amd64" + +DESCRIPTION="Prometheus exporter for MySQL server metrics" +HOMEPAGE="https://github.com/prometheus/mysqld_exporter" +SRC_URI="${ARCHIVE_URI}" +LICENSE="Apache-2.0" +SLOT="0" +IUSE="" + +DEPEND="dev-util/promu" + +pkg_setup() { + enewgroup ${PN} + enewuser ${PN} -1 -1 /var/lib/mysqld_exporter ${PN} +} + +src_prepare() { + default + sed -i -e "s/{{.Revision}}/${MYSQLD_EXPORTER_COMMIT}/" src/${EGO_PN}/.promu.yml || die +} + +src_compile() { + pushd src/${EGO_PN} || die + mkdir -p bin || die + GOPATH="${S}" promu build -v --prefix bin || die + popd || die +} + +src_install() { + pushd src/${EGO_PN} || die + dobin bin/mysqld_exporter + dodoc {README,CHANGELOG,CONTRIBUTING}.md + popd || die + + keepdir /var/lib/mysqld_exporter /var/log/mysqld_exporter + fowners ${PN}:${PN} /var/lib/mysqld_exporter /var/log/mysqld_exporter + fperms 0770 /var/lib/mysqld_exporter + + newinitd "${FILESDIR}"/${PN}-r1.initd ${PN} + newconfd "${FILESDIR}"/${PN}-r1.confd ${PN} + + systemd_dounit "${FILESDIR}/${PN}.service" + + insinto /etc/logrotate.d/ + newins "${FILESDIR}"/${PN}.logrotate ${PN} +} + +pkg_postinst() { + if [[ -z "${REPLACING_VERSIONS}" ]]; then + # This is a new installation + elog "Create \"${EROOT%/}/var/lib/mysqld_exporter/.my.cnf\" to read MySQL credentials from file." + else + local _replacing_version= + for _replacing_version in ${REPLACING_VERSIONS}; do + if ! ver_test "${_replacing_version}" -ge "0.11.0"; then + elog "Starting with ${PN}-0.11.0, command-line flags will require double dashes (--)." + elog "You must update your configuration or ${PN} won't start." + + break + fi + done + fi +}