Skip to content

Commit 3304b37

Browse files
committed
Add metrics exporter service
This was still missing after adding the metrics exporter binary.
1 parent 955800f commit 3304b37

File tree

7 files changed

+72
-4
lines changed

7 files changed

+72
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[Unit]
2+
Description=Statime metrics exporter
3+
Documentation=https://github.com/pendulum-project/statime
4+
After=statime.service
5+
Requires=statime.service
6+
Conflicts=
7+
8+
[Service]
9+
Type=simple
10+
Restart=always
11+
ExecStart=/usr/bin/statime-metrics-exporter
12+
Environment="RUST_LOG=info"
13+
RuntimeDirectory=statime-observe
14+
User=statime-observe
15+
Group=statime-observe
16+
17+
[Install]
18+
WantedBy=multi-user.target

pkg/deb/postinst

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ set -e
44

55
STATIME_HOME="/var/lib/statime/"
66
STATIME_USER="statime"
7+
STATIME_OBSERVE_HOME="/var/lib/statime-observe/"
8+
STATIME_OBSERVE_USER="statime-observe"
79

810
create_user() {
911
if ! id ${STATIME_USER} > /dev/null 2>&1; then
1012
adduser --system --home "${STATIME_HOME}" --group ${STATIME_USER}
1113
fi
14+
if ! id ${STATIME_OBSERVE_USER} > /dev/null 2>&1; then
15+
adduser --system --home "${STATIME_OBSERVE_HOME}" --group ${STATIME_OBSERVE_USER}
16+
fi
1217
}
1318

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

41+
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
42+
if deb-systemd-helper debian-installed statime-metrics-exporter.service; then
43+
# This will only remove masks created by d-s-h on package removal.
44+
deb-systemd-helper unmask statime-metrics-exporter.service >/dev/null || true
45+
46+
if deb-systemd-helper --quiet was-enabled statime-metrics-exporter.service; then
47+
# Create new symlinks, if any.
48+
deb-systemd-helper enable statime-metrics-exporter.service >/dev/null || true
49+
fi
50+
fi
51+
52+
# Update the statefile to add new symlinks (if any), which need to be cleaned
53+
# up on purge. Also remove old symlinks.
54+
deb-systemd-helper update-state statime-metrics-exporter.service >/dev/null || true
55+
fi
56+
3657
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
3758
if [ -d /run/systemd/system ]; then
3859
systemctl --system daemon-reload >/dev/null || true
@@ -42,12 +63,13 @@ if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-decon
4263
_dh_action=start
4364
fi
4465
deb-systemd-invoke $_dh_action statime.service >/dev/null || true
66+
deb-systemd-invoke $_dh_action statime-metrics-exporter.service >/dev/null || true
4567
fi
4668

47-
if [ -d /run/udev ]; then
48-
udevadm control -R
49-
udevadm trigger
50-
fi
69+
if [ -d /run/udev ]; then
70+
udevadm control -R
71+
udevadm trigger
72+
fi
5173
fi
5274

5375
#DEBHELPER#

pkg/deb/postrm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fi
2121
if [ "$1" = "remove" ]; then
2222
if [ -x "/usr/bin/deb-systemd-helper" ]; then
2323
deb-systemd-helper mask statime.service >/dev/null || true
24+
deb-systemd-helper mask statime-metrics-exporter.service >/dev/null || true
2425
fi
2526

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

3841
if [ -d /run/udev ]; then

pkg/deb/prerm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ set -e
33

44
if [ -d /run/systemd/system ] && [ "$1" = remove ]; then
55
deb-systemd-invoke stop statime.service >/dev/null || true
6+
deb-systemd-invoke stop statime-metrics-exporter.service >/dev/null || true
67
fi

pkg/rpm/scriptlets.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ fi
1010
STATIME_USER=statime
1111
STATIME_HOME_DIR="/var/lib/statime"
1212
STATIME_HOME_DIR_PERMS=700
13+
STATIME_OBSERVE_USER=statime-observe
14+
STATIME_OBSERVE_HOME_DIR="/var/lib/statime-observe"
15+
STATIME_OBSERVE_HOME_DIR_PERMS=700
1316
1417
create_user() {
1518
if ! id ${STATIME_USER} > /dev/null 2>&1; then
@@ -22,10 +25,22 @@ create_user() {
2225
chown -R ${STATIME_USER}:${STATIME_USER} ${STATIME_HOME_DIR}
2326
# Ensure that the home directory has the correct permissions
2427
chmod ${STATIME_HOME_DIR_PERMS} ${STATIME_HOME_DIR}
28+
29+
if ! id ${STATIME_OBSERVE_USER} > /dev/null 2>&1; then
30+
# According to the CentOS 7 useradd man page:
31+
# --user-group causes a group by the same name as the user to be created
32+
# --create-home should force creation of a home dir even for a system account.
33+
useradd --home-dir ${STATIME_OBSERVE_HOME_DIR} --system --create-home --user-group ${STATIME_OBSERVE_USER}
34+
fi
35+
# Ensure that the home directory has the correct ownership
36+
chown -R ${STATIME_OBSERVE_USER}:${STATIME_USER} ${STATIME_OBSERVE_HOME_DIR}
37+
# Ensure that the home directory has the correct permissions
38+
chmod ${STATIME_OBSERVE_HOME_DIR_PERMS} ${STATIME_OBSERVE_HOME_DIR}
2539
}
2640
2741
init_systemd_service() {
2842
systemd_post statime.service
43+
systemd_post statime-metrics-exporter.service
2944
systemd_triggers
3045
}
3146
@@ -54,6 +69,7 @@ if [ $1 -eq 0 ] ; then
5469
# Package removal, not upgrade
5570
# Run commands equivalent to what the RPM systemd macros would do
5671
systemd_preun statime.service
72+
systemd_preun statime-metrics-exporter.service
5773
systemd_triggers
5874
fi
5975
'''
@@ -65,6 +81,7 @@ post_uninstall_script = '''
6581
if [ $1 -ge 1 ] ; then
6682
# Run commands equivalent to what the RPM systemd macros would do
6783
systemd_postun_with_restart statime.service
84+
systemd_postun_with_restart statime-metrics-exporter.service
6885
systemd_triggers
6986
fi
7087

pkg/test-scripts/test-statime.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ case $1 in
1212
echo -e "\nSTATIME HELP OUTPUT:"
1313
/usr/bin/statime --help
1414

15+
# Ensure deamon is present
16+
echo -e "\nSTATIME METRICS EXPORTER HELP OUTPUT:"
17+
/usr/bin/statime-metrics-exporter --help
18+
1519
# # Ensure that the systemd service is not running by default
1620
# ! systemctl is-active statime.service --quiet
21+
# ! systemctl is-active statime-metrics-exporter.service --quiet
1722
;;
1823
esac

statime-linux/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ assets = [
6060
["docs/examples/conf/statime.toml.default", "/etc/statime/statime.toml", "644"],
6161
["docs/examples/conf/statime.preset", "/lib/systemd/system-preset/50-statime.preset", "644"],
6262
["docs/examples/conf/statime.service", "/lib/systemd/system/statime.service", "644"],
63+
["docs/examples/conf/statime-metrics-exporter.service", "/lib/systemd/system/statime-metrics-exporter.service", "644"],
6364
["docs/examples/conf/41-statime.rules", "/etc/udev/rules.d/41-statime.rules", "644"],
6465
["../COPYRIGHT", "/usr/share/doc/statime/COPYRIGHT", "644"],
6566
["../LICENSE-APACHE", "/usr/share/doc/statime/LICENSE-APACHE", "644"],
@@ -85,6 +86,7 @@ assets = [
8586
{ source = "docs/examples/conf/statime.toml.default", dest = "/etc/statime/statime.toml", mode = "644", config = true },
8687
{ source = "docs/examples/conf/statime.preset", dest = "/lib/systemd/system-preset/50-statime.preset", mode = "644" },
8788
{ source = "docs/examples/conf/statime.service", dest = "/lib/systemd/system/statime.service", mode = "644" },
89+
{ source = "docs/examples/conf/statime-metrics-exporter.service", dest = "/lib/systemd/system/statime-metrics-exporter.service", mode = "644" },
8890
{ source = "docs/examples/conf/41-statime.rules", dest = "/etc/udev/rules.d/41-statime.rules", mode = "644", config = true },
8991
{ source = "../COPYRIGHT", dest = "/usr/share/doc/statime/COPYRIGHT", mode = "644", doc = true },
9092
{ source = "../LICENSE-APACHE", dest = "/usr/share/doc/statime/LICENSE-APACHE", mode = "644", doc = true },

0 commit comments

Comments
 (0)