使用软件时钟节省时间
OpenRC 有其自己保存时钟的方法,称为 “swclock”,我就是用的这个方法。通常,swclock 在保存时间时,只是简单地更改一个符号链接,例如 /sbin/openrc-run -> /sbin/openrc 。
然而,当恢复时,这将具有软件包打包的时间,因为 Alpine Linux 在启动时解压软件包,然后从 apkprov 移动已配置的配置文件。您需要进行这些更改以指定一个文件。
/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"
然后创建该文件
touch /etc/swclock_saved_time
最后,将 swclock 添加到启动运行级别
rc-update add swclock boot
您还需要在您的 apkprov 中包含新的 init 脚本,否则它将被 OpenRC 软件包中的脚本覆盖。
lbu include /etc/init.d/swclock