Martin Pitt [2015-02-16 16:41 +0100]:
> For master (i. e. testing/jessie), I prepared and tested the attached
> patch.

Slightly refined version 2 of the patch: renamed to
hwclock-save.service to not get mingled with util-linux'
hwclock.service.

Martin
-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
From a32678de07b3a89028e54d5bceff5479ad1169c3 Mon Sep 17 00:00:00 2001
From: Martin Pitt <martin.p...@ubuntu.com>
Date: Mon, 16 Feb 2015 16:14:23 +0100
Subject: [PATCH] Add hwclock-save.service to sync the system clock to the
 hardware clock on shutdown

This provides monotonic time for reboots. Thanks to Stefan Fritsch for the
initial unit.

Note: this is a hack for jessie; the next Debian release will enable timesyncd
by default.

Closes: #755722
---
 debian/changelog                  |  9 +++++++++
 debian/extra/hwclock-save.service | 14 ++++++++++++++
 debian/rules                      |  2 +-
 debian/systemd.postinst           |  4 ++++
 4 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 debian/extra/hwclock-save.service

diff --git a/debian/changelog b/debian/changelog
index 6d81277..1493538 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,12 @@
+systemd (215-13) UNRELEASED; urgency=medium
+
+  * Add hwclock-save.service to sync the system clock to the hardware clock on
+    shutdown, to provide monotonic time for reboots. (Note: this is a hack for
+    jessie; the next Debian release will enable timesyncd by default).
+    (Closes: #755722)
+
+ -- Martin Pitt <mp...@debian.org>  Mon, 16 Feb 2015 16:11:12 +0100
+
 systemd (215-12) unstable; urgency=medium
 
   [ Martin Pitt ]
diff --git a/debian/extra/hwclock-save.service b/debian/extra/hwclock-save.service
new file mode 100644
index 0000000..1e0f99a
--- /dev/null
+++ b/debian/extra/hwclock-save.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Synchronise Hardware Clock to System Clock
+DefaultDependencies=no
+Before=shutdown.target
+ConditionFileIsExecutable=!/usr/sbin/ntpd
+ConditionFileIsExecutable=!/usr/sbin/openntpd
+ConditionFileIsExecutable=!/usr/sbin/chrony
+
+[Service]
+Type=oneshot
+ExecStart=/sbin/hwclock -D --systohc
+
+[Install]
+WantedBy=reboot.target halt.target poweroff.target
diff --git a/debian/rules b/debian/rules
index 4f79678..92bd007 100755
--- a/debian/rules
+++ b/debian/rules
@@ -183,7 +183,7 @@ override_dh_install:
 		debian/systemd/lib/lsb/init-functions.d/40-systemd
 	install --mode=644 debian/tmpfiles.d/debian.conf \
 		debian/systemd/usr/lib/tmpfiles.d/
-	install --mode=644 debian/debian-fixup.service debian/ifup@.service debian/extra/getty-static.service \
+	install --mode=644 debian/debian-fixup.service debian/ifup@.service debian/extra/getty-static.service debian/extra/hwclock-save.service \
 		debian/systemd/lib/systemd/system/
 	install -D --mode=644 debian/extra/network-pre.conf \
 		debian/systemd/lib/systemd/system/networking.service.d/network-pre.conf
diff --git a/debian/systemd.postinst b/debian/systemd.postinst
index 488df32..de92c57 100644
--- a/debian/systemd.postinst
+++ b/debian/systemd.postinst
@@ -131,6 +131,10 @@ if dpkg --compare-versions "$2" lt "214-1"; then
     systemctl enable remote-fs.target || true
 fi
 
+if dpkg --compare-versions "$2" lt "215-13"; then
+    systemctl enable hwclock-save.service || true
+fi
+
 # Re-run systemctl enable for any service that was enabled when preinst was run.
 if dpkg --compare-versions "$2" ge "204"; then
     while read UNIT ; do
-- 
2.1.4

Attachment: signature.asc
Description: Digital signature

Reply via email to