diff --git a/docs/examples/conf/statime-metrics-exporter.service b/docs/examples/conf/statime-metrics-exporter.service new file mode 100644 index 000000000..22fb911fb --- /dev/null +++ b/docs/examples/conf/statime-metrics-exporter.service @@ -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 diff --git a/pkg/deb/postinst b/pkg/deb/postinst index 3b77d3b7a..3c8215ff9 100644 --- a/pkg/deb/postinst +++ b/pkg/deb/postinst @@ -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 @@ -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 @@ -42,12 +63,13 @@ if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-decon _dh_action=start fi deb-systemd-invoke $_dh_action statime.service >/dev/null || true + deb-systemd-invoke $_dh_action 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# diff --git a/pkg/deb/postrm b/pkg/deb/postrm index 9194cfd03..02fd87541 100644 --- a/pkg/deb/postrm +++ b/pkg/deb/postrm @@ -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 @@ -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 diff --git a/pkg/deb/prerm b/pkg/deb/prerm index e26b245cd..4242fd691 100755 --- a/pkg/deb/prerm +++ b/pkg/deb/prerm @@ -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 diff --git a/pkg/rpm/scriptlets.toml b/pkg/rpm/scriptlets.toml index 25ed80c3c..8fd85575b 100644 --- a/pkg/rpm/scriptlets.toml +++ b/pkg/rpm/scriptlets.toml @@ -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 @@ -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 } @@ -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 ''' @@ -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 diff --git a/pkg/test-scripts/test-statime.sh b/pkg/test-scripts/test-statime.sh index 11e2a9528..2703c39dc 100644 --- a/pkg/test-scripts/test-statime.sh +++ b/pkg/test-scripts/test-statime.sh @@ -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 diff --git a/statime-linux/Cargo.toml b/statime-linux/Cargo.toml index 3af414cd4..857e6e75e 100644 --- a/statime-linux/Cargo.toml +++ b/statime-linux/Cargo.toml @@ -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"], @@ -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 },