Skip to content

Commit

Permalink
Add metrics exporter service
Browse files Browse the repository at this point in the history
This was still missing after adding the metrics exporter binary.
  • Loading branch information
tdittr authored and davidv1992 committed Feb 7, 2025
1 parent 8d706b7 commit b9b1269
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
18 changes: 18 additions & 0 deletions docs/examples/conf/statime-metrics-exporter.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=Statime metrics exporter
Documentation=https://github.com/pendulum-project/statime
After=statime.service
Requires=statime.service
Conflicts=

[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/statime-metrics-exporter
Environment="RUST_LOG=info"
RuntimeDirectory=statime-observe
User=statime-observe
Group=statime-observe

[Install]
WantedBy=multi-user.target
31 changes: 26 additions & 5 deletions pkg/deb/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ set -e

STATIME_HOME="/var/lib/statime/"
STATIME_USER="statime"
STATIME_OBSERVE_HOME="/var/lib/statime-observe/"
STATIME_OBSERVE_USER="statime-observe"

create_user() {
if ! id ${STATIME_USER} > /dev/null 2>&1; then
adduser --system --home "${STATIME_HOME}" --group ${STATIME_USER}
fi
if ! id ${STATIME_OBSERVE_USER} > /dev/null 2>&1; then
adduser --system --home "${STATIME_OBSERVE_HOME}" --group ${STATIME_OBSERVE_USER}
fi
}

case "$1" in
Expand All @@ -33,6 +38,22 @@ if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-decon
deb-systemd-helper update-state statime.service >/dev/null || true
fi

if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
if deb-systemd-helper debian-installed statime-metrics-exporter.service; then
# This will only remove masks created by d-s-h on package removal.
deb-systemd-helper unmask statime-metrics-exporter.service >/dev/null || true

if deb-systemd-helper --quiet was-enabled statime-metrics-exporter.service; then
# Create new symlinks, if any.
deb-systemd-helper enable statime-metrics-exporter.service >/dev/null || true
fi
fi

# Update the statefile to add new symlinks (if any), which need to be cleaned
# up on purge. Also remove old symlinks.
deb-systemd-helper update-state statime-metrics-exporter.service >/dev/null || true
fi

if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
Expand All @@ -41,13 +62,13 @@ if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-decon
else
_dh_action=start
fi
deb-systemd-invoke $_dh_action statime.service >/dev/null || true
deb-systemd-invoke $_dh_action statime.service statime-metrics-exporter.service >/dev/null || true
fi

if [ -d /run/udev ]; then
udevadm control -R
udevadm trigger
fi
if [ -d /run/udev ]; then
udevadm control -R
udevadm trigger
fi
fi

#DEBHELPER#
3 changes: 3 additions & 0 deletions pkg/deb/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fi
if [ "$1" = "remove" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper mask statime.service >/dev/null || true
deb-systemd-helper mask statime-metrics-exporter.service >/dev/null || true
fi

if [ -d /run/udev ]; then
Expand All @@ -33,6 +34,8 @@ if [ "$1" = "purge" ]; then
if [ -x "/usr/bin/deb-systemd-helper" ]; then
deb-systemd-helper purge statime.service >/dev/null || true
deb-systemd-helper unmask statime.service >/dev/null || true
deb-systemd-helper purge statime-metrics-exporter.service >/dev/null || true
deb-systemd-helper unmask statime-metrics-exporter.service >/dev/null || true
fi

if [ -d /run/udev ]; then
Expand Down
1 change: 1 addition & 0 deletions pkg/deb/prerm
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ set -e

if [ -d /run/systemd/system ] && [ "$1" = remove ]; then
deb-systemd-invoke stop statime.service >/dev/null || true
deb-systemd-invoke stop statime-metrics-exporter.service >/dev/null || true
fi
17 changes: 17 additions & 0 deletions pkg/rpm/scriptlets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ fi
STATIME_USER=statime
STATIME_HOME_DIR="/var/lib/statime"
STATIME_HOME_DIR_PERMS=700
STATIME_OBSERVE_USER=statime-observe
STATIME_OBSERVE_HOME_DIR="/var/lib/statime-observe"
STATIME_OBSERVE_HOME_DIR_PERMS=700
create_user() {
if ! id ${STATIME_USER} > /dev/null 2>&1; then
Expand All @@ -22,10 +25,22 @@ create_user() {
chown -R ${STATIME_USER}:${STATIME_USER} ${STATIME_HOME_DIR}
# Ensure that the home directory has the correct permissions
chmod ${STATIME_HOME_DIR_PERMS} ${STATIME_HOME_DIR}
if ! id ${STATIME_OBSERVE_USER} > /dev/null 2>&1; then
# According to the CentOS 7 useradd man page:
# --user-group causes a group by the same name as the user to be created
# --create-home should force creation of a home dir even for a system account.
useradd --home-dir ${STATIME_OBSERVE_HOME_DIR} --system --create-home --user-group ${STATIME_OBSERVE_USER}
fi
# Ensure that the home directory has the correct ownership
chown -R ${STATIME_OBSERVE_USER}:${STATIME_USER} ${STATIME_OBSERVE_HOME_DIR}
# Ensure that the home directory has the correct permissions
chmod ${STATIME_OBSERVE_HOME_DIR_PERMS} ${STATIME_OBSERVE_HOME_DIR}
}
init_systemd_service() {
systemd_post statime.service
systemd_post statime-metrics-exporter.service
systemd_triggers
}
Expand Down Expand Up @@ -54,6 +69,7 @@ if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
# Run commands equivalent to what the RPM systemd macros would do
systemd_preun statime.service
systemd_preun statime-metrics-exporter.service
systemd_triggers
fi
'''
Expand All @@ -65,6 +81,7 @@ post_uninstall_script = '''
if [ $1 -ge 1 ] ; then
# Run commands equivalent to what the RPM systemd macros would do
systemd_postun_with_restart statime.service
systemd_postun_with_restart statime-metrics-exporter.service
systemd_triggers
fi
Expand Down
5 changes: 5 additions & 0 deletions pkg/test-scripts/test-statime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ case $1 in
echo -e "\nSTATIME HELP OUTPUT:"
/usr/bin/statime --help

# Ensure deamon is present
echo -e "\nSTATIME METRICS EXPORTER HELP OUTPUT:"
/usr/bin/statime-metrics-exporter --help

# # Ensure that the systemd service is not running by default
# ! systemctl is-active statime.service --quiet
# ! systemctl is-active statime-metrics-exporter.service --quiet
;;
esac
2 changes: 2 additions & 0 deletions statime-linux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ assets = [
["docs/examples/conf/statime.toml.default", "/etc/statime/statime.toml", "644"],
["docs/examples/conf/statime.preset", "/lib/systemd/system-preset/50-statime.preset", "644"],
["docs/examples/conf/statime.service", "/lib/systemd/system/statime.service", "644"],
["docs/examples/conf/statime-metrics-exporter.service", "/lib/systemd/system/statime-metrics-exporter.service", "644"],
["docs/examples/conf/41-statime.rules", "/etc/udev/rules.d/41-statime.rules", "644"],
["../COPYRIGHT", "/usr/share/doc/statime/COPYRIGHT", "644"],
["../LICENSE-APACHE", "/usr/share/doc/statime/LICENSE-APACHE", "644"],
Expand All @@ -85,6 +86,7 @@ assets = [
{ source = "docs/examples/conf/statime.toml.default", dest = "/etc/statime/statime.toml", mode = "644", config = true },
{ source = "docs/examples/conf/statime.preset", dest = "/lib/systemd/system-preset/50-statime.preset", mode = "644" },
{ source = "docs/examples/conf/statime.service", dest = "/lib/systemd/system/statime.service", mode = "644" },
{ source = "docs/examples/conf/statime-metrics-exporter.service", dest = "/lib/systemd/system/statime-metrics-exporter.service", mode = "644" },
{ source = "docs/examples/conf/41-statime.rules", dest = "/etc/udev/rules.d/41-statime.rules", mode = "644", config = true },
{ source = "../COPYRIGHT", dest = "/usr/share/doc/statime/COPYRIGHT", mode = "644", doc = true },
{ source = "../LICENSE-APACHE", dest = "/usr/share/doc/statime/LICENSE-APACHE", mode = "644", doc = true },
Expand Down

0 comments on commit b9b1269

Please sign in to comment.