diff options
Diffstat (limited to 'recipes-core/systemd/timestamp-service')
-rw-r--r-- | recipes-core/systemd/timestamp-service/load-timestamp.sh | 21 | ||||
-rw-r--r-- | recipes-core/systemd/timestamp-service/timestamp.service | 12 |
2 files changed, 33 insertions, 0 deletions
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 |