From c1c098080b8ab5b3c612d4a86c03bdade69fe3e8 Mon Sep 17 00:00:00 2001 From: Max Krummenacher Date: Mon, 7 Jan 2019 19:41:45 +0100 Subject: timestamp-service: import from angstrom Signed-off-by: Max Krummenacher --- recipes-core/systemd/timestamp-service.bb | 30 ++++++++++++++++++++++ .../systemd/timestamp-service/load-timestamp.sh | 21 +++++++++++++++ .../systemd/timestamp-service/timestamp.service | 12 +++++++++ 3 files changed, 63 insertions(+) create mode 100644 recipes-core/systemd/timestamp-service.bb create mode 100644 recipes-core/systemd/timestamp-service/load-timestamp.sh create mode 100644 recipes-core/systemd/timestamp-service/timestamp.service diff --git a/recipes-core/systemd/timestamp-service.bb b/recipes-core/systemd/timestamp-service.bb new file mode 100644 index 0000000..b1d4902 --- /dev/null +++ b/recipes-core/systemd/timestamp-service.bb @@ -0,0 +1,30 @@ +DESCRIPTION = "Poor mans RTC using timestamps" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" + +inherit allarch systemd + +SRC_URI = "file://timestamp.service \ + file://load-timestamp.sh \ + " + +do_compile() { + : +} + + +do_install () { + install -d ${D}/${bindir} + + install -m 0755 ${WORKDIR}/load-timestamp.sh ${D}/${bindir} + + install -d ${D}/${base_libdir}/systemd/system + install -m 0644 ${WORKDIR}/timestamp.service ${D}/${base_libdir}/systemd/system/ +} + +NATIVE_SYSTEMD_SUPPORT = "1" +SYSTEMD_PACKAGES = "${PN}" +SYSTEMD_SERVICE_${PN} = "timestamp.service" + +FILES_${PN} += "${base_libdir}/systemd" + diff --git a/recipes-core/systemd/timestamp-service/load-timestamp.sh b/recipes-core/systemd/timestamp-service/load-timestamp.sh new file mode 100644 index 0000000..6902d1d --- /dev/null +++ b/recipes-core/systemd/timestamp-service/load-timestamp.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +if [ "$1" != "--save" ] ; then + +# Set the system clock from timestamp file +# if the timestamp is 1 second or more recent +# than the current systemtime. + +SYSTEMDATE=$(/bin/date -u "+%4Y%2m%2d%2H%2M%2S") + +TIMESTAMP=$(/bin/cat /etc/timestamp 2>/dev/null) + +if [ $SYSTEMDATE -lt $TIMESTAMP ] 2>/dev/null ; then + echo "Update systemtime from /etc/timestamp" + /bin/date -u ${TIMESTAMP:4:8}${TIMESTAMP:0:4}.${TIMESTAMP:(-2)} +fi + +else +# Store the current systemtime in /etc/timestamp + /bin/date -u +%4Y%2m%2d%2H%2M%2S > /etc/timestamp +fi diff --git a/recipes-core/systemd/timestamp-service/timestamp.service b/recipes-core/systemd/timestamp-service/timestamp.service new file mode 100644 index 0000000..9be5056 --- /dev/null +++ b/recipes-core/systemd/timestamp-service/timestamp.service @@ -0,0 +1,12 @@ +[Unit] +Description=Timestamping service +ConditionPathExists=/etc/timestamp +After=remount-rootfs.service + +[Service] +RemainAfterExit=yes +ExecStart=/usr/bin/load-timestamp.sh +ExecStop=/usr/bin/load-timestamp.sh --save + +[Install] +WantedBy=basic.target -- cgit v1.2.3