Saving time with Software Clock

From Alpine Linux
Revision as of 10:40, 10 August 2015 by Sillysausage (talk | contribs) (Created page with " OpenRC has it's own method for saving the clock called "swclock", that's what I went with. Normally swclock simply changes a symlink ie /sbin/openrc-run -> /sbin/openrc when...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

OpenRC has it's own method for saving the clock called "swclock", that's what I went with. Normally swclock simply changes a symlink ie /sbin/openrc-run -> /sbin/openrc when it saves the time.

However this when restored will have the time that the package was put together, because Alpine Linux unpacks packages on boot, then moves the provisioned configs from apkprov. You will need to make these changes to specify a file.

/etc/init.d/swclock

--- swclock.old
+++ swclock
@@ -3,6 +3,7 @@
 # Released under the 2-clause BSD license.
 
 description="Sets the local clock to the mtime of a given file."
+clock_file=${clock_file:-/etc/rc.conf}
 
 depend()
 {
@@ -17,7 +18,7 @@
 {
 	ebegin "Setting the local clock based on last shutdown time"
 	if ! swclock 2> /dev/null; then
-	swclock --warn /sbin/openrc-run
+	swclock --warn $clock_file
 	fi
 	eend $?
 }
@@ -25,6 +26,6 @@
 stop()
 {
 	ebegin "Saving the shutdown time"
-	swclock --save
+	swclock --save $clock_file
 	eend $?
 }

/etc/conf.d/swclock

clock_file="/etc/swclock_saved_time"

Then touch the file:

touch /etc/swclock_saved_time

and finally add swclock to the boot run level

rc-update add swclock boot

You will also need to include the new init script in your apkprov, otherwise it will be overwritten with the one from the OpenRC package.

lbu include /etc/init.d/swclock