K01hwclock.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: hwclock
  4. # Required-Start:
  5. # Required-Stop: mountdevsubfs
  6. # Should-Stop: umountfs
  7. # Default-Start: S
  8. # Default-Stop: 0 6
  9. # Short-Description: Save system clock to hardware on shutdown.
  10. ### END INIT INFO
  11. # Note: this init script and related code is only useful if you
  12. # run a sysvinit system, without NTP synchronization.
  13. if [ -e /run/systemd/system ] ; then
  14. exit 0
  15. fi
  16. unset TZ
  17. hwclocksh()
  18. {
  19. HCTOSYS_DEVICE=rtc0
  20. [ ! -x /sbin/hwclock ] && return 0
  21. [ ! -r /etc/default/rcS ] || . /etc/default/rcS
  22. [ ! -r /etc/default/hwclock ] || . /etc/default/hwclock
  23. . /lib/lsb/init-functions
  24. verbose_log_action_msg() { [ "$VERBOSE" = no ] || log_action_msg "$@"; }
  25. case "$1" in
  26. start)
  27. # start is handled by /usr/lib/udev/rules.d/85-hwclock.rules.
  28. return 0
  29. ;;
  30. stop|restart|reload|force-reload)
  31. # Updates the Hardware Clock with the System Clock time.
  32. # This will *override* any changes made to the Hardware Clock,
  33. # for example by the Linux kernel when NTP is in use.
  34. log_action_msg "Saving the system clock to /dev/$HCTOSYS_DEVICE"
  35. if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --systohc; then
  36. verbose_log_action_msg "Hardware Clock updated to `date`"
  37. fi
  38. ;;
  39. show)
  40. /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --show
  41. ;;
  42. *)
  43. log_success_msg "Usage: hwclock.sh {stop|reload|force-reload|show}"
  44. log_success_msg " stop and reload set hardware (RTC) clock from kernel (system) clock"
  45. return 1
  46. ;;
  47. esac
  48. }
  49. hwclocksh "$@"