Skip to content

Commit

Permalink
sql_exporter: adding package plus config, user and group
Browse files Browse the repository at this point in the history
  • Loading branch information
leomuso committed Apr 16, 2024
1 parent b5857ab commit d96b032
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
8 changes: 5 additions & 3 deletions app-metrics/sql_exporter/files/sql_exporter.init.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ name="sql_exporter daemon"
description="SQL Exporter allows to run custom queries against a database"
command="/usr/bin/sql_exporter"
command_args="-config.file /etc/sql_exporter/sql_exporter.yml"
start_stop_daemon_args="--user sql_exporter"
output_log="/var/log/sql_exporter/sql_exporter.log"
error_log="/var/log/sql_exporter/sql_exporter.log"
stdout_log="/var/log/sql_exporter/sql_exporter.log"
stderr_log="/var/log/sql_exporter/sql_exporter.log"
start_stop_daemon_args="--background --user sql_exporter \
--stdout $stdout_log \
--stderr $stderr_log"

depend() {
need net
Expand Down
6 changes: 3 additions & 3 deletions app-metrics/sql_exporter/files/sql_exporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# jobs is a map of jobs, define any number but please keep the connection usage on the DBs in mind
jobs:
# each job needs a unique name, it's used for logging and as an default label
- name: "example"
- name: "postgres"
# interval defined the pause between the runs of this job
interval: '5m'
# cron_schedule when to execute the job in the standard CRON syntax
# if specified, the interval is ignored
cron_schedule: "0 0 * * *"
cron_schedule: "* * * * *"
# connections is an array of connection URLs
# each query will be executed on each connection
connections:
- 'postgres://postgres@localhost/postgres?sslmode=disable'
- 'postgres://sql_exporter@/?host=/run/postgresql&dbname=postgres&sslmode=disable'
# startup_sql is an array of SQL statements
# each statements is executed once after connecting
startup_sql:
Expand Down
31 changes: 17 additions & 14 deletions app-metrics/sql_exporter/sql_exporter-0.5.3.ebuild
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,34 @@ EGO_PN="github.com/justwatchcom/sql_exporter"

src_prepare() {
default
cd "${S}" || die
cd "${S}"
export GO111MODULE=auto
}

src_compile() {
export GOPATH="${S}"
cd "${S}/src/${EGO_PN}" || die
echo "compiling from $(pwd)" || die
go build -o "${S}/bin/sql_exporter" || die "Failed to build sql_exporter"
cd "${S}/src/${EGO_PN}"
echo "compiling from $(pwd)"
go build -o "${S}/bin/sql_exporter"
}

src_test() {
cd "${S}/src/${EGO_PN}" || die
go test -v ./... || die "Tests failed"
cd "${S}/src/${EGO_PN}"
go test -v ./...
}

src_install() {
dobin "${S}/bin/sql_exporter"
newinitd "${FILESDIR}/sql_exporter.init.d" sql_exporter
dosym /etc/init.d/sql_exporter /etc/runlevels/default/sql_exporter || die
dobin "${S}/bin/sql_exporter"
newinitd "${FILESDIR}/sql_exporter.init.d" sql_exporter
dosym /etc/init.d/sql_exporter /etc/runlevels/default/sql_exporter

insinto /etc/sql_exporter
doins "${FILESDIR}/sql_exporter.yml"
insinto /etc/sql_exporter
doins "${FILESDIR}/sql_exporter.yml"

# Create log directory and file
dodir /var/log/sql_exporter
touch "${ED}"/var/log/sql_exporter/sql_exporter.log || die "failed to create log file"
# Create log directory and file
dodir /var/log/sql_exporter
touch "${ED}"/var/log/sql_exporter/sql_exporter.log

# Change ownership of the log file to sql_exporter
chown sql_exporter:sql_exporter "${ED}"/var/log/sql_exporter/sql_exporter.log
}

0 comments on commit d96b032

Please sign in to comment.