chronyd.init 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2013 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. depend() {
  5. use dns
  6. }
  7. checkconfig() {
  8. # Note that /etc/chrony/chrony.keys is *NOT* checked. This
  9. # is because the user may have specified another key
  10. # file, and we don't want to force the user to use that
  11. # exact name for the key file.
  12. if [ ! -f "${CFGFILE}" ] ; then
  13. eerror "Please create ${CFGFILE} and the"
  14. eerror "chrony key file (usually /etc/chrony/chrony.keys)"
  15. eerror "by using the"
  16. eerror ""
  17. eerror " chrony.conf.example"
  18. eerror " chrony.keys.example"
  19. eerror ""
  20. eerror "files (from the documentation directory)"
  21. eerror "as templates."
  22. return 1
  23. else
  24. # Actually, I tried it, and chrony seems to ignore the pidfile
  25. # option. I'm going to leave it here anyway, since you never
  26. # know if it might be handy
  27. PIDFILE=`awk '/^ *pidfile/{print $2}' "${CFGFILE}"`
  28. fi
  29. return 0
  30. }
  31. setxtrarg() {
  32. if [ -c /dev/rtc ]; then
  33. grep -q '^rtcfile' "${CFGFILE}" && ARGS="${ARGS} -s"
  34. fi
  35. grep -q '^dumponexit$' "${CFGFILE}" && ARGS="${ARGS} -r"
  36. return 0
  37. }
  38. start() {
  39. checkconfig || return $?
  40. setxtrarg
  41. [ -n "${PIDFILE}" ] || PIDFILE=/run/chronyd.pid
  42. ebegin "Starting chronyd"
  43. start-stop-daemon --start --background --quiet \
  44. --exec /usr/sbin/chronyd \
  45. --pidfile "${PIDFILE}" \
  46. -- -f "${CFGFILE}" ${ARGS}
  47. eend $? "Failed to start chronyd"
  48. }
  49. stop() {
  50. checkconfig || return $?
  51. [ -n "${PIDFILE}" ] || PIDFILE=/run/chronyd.pid
  52. ebegin "Stopping chronyd"
  53. start-stop-daemon --stop --quiet \
  54. --pidfile "${PIDFILE}"
  55. eend $? "Failed to stop chronyd"
  56. }