chronyd.init-r1 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 \
  44. --start \
  45. --quiet \
  46. --exec /usr/sbin/chronyd \
  47. --pidfile "${PIDFILE}" \
  48. -- -f "${CFGFILE}" ${ARGS}
  49. eend $? "Failed to start chronyd"
  50. }
  51. stop() {
  52. checkconfig || return $?
  53. [ -n "${PIDFILE}" ] || PIDFILE=/run/chronyd.pid
  54. ebegin "Stopping chronyd"
  55. start-stop-daemon \
  56. --stop \
  57. --quiet \
  58. --pidfile "${PIDFILE}"
  59. eend $? "Failed to stop chronyd"
  60. }