fcron.initd 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/openrc-run
  2. # Copyright 1999-2017 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. FCRON_INSTANCE="${SVCNAME##*.}"
  5. FCRON_OPTS=${FCRON_OPTS:-""}
  6. if [ -n "${FCRON_INSTANCE}" ] && [ "${SVCNAME}" != "fcron" ]; then
  7. FCRON_CONFIGFILE="/etc/fcron/fcron.${FCRON_INSTANCE}.conf"
  8. else
  9. FCRON_CONFIGFILE="/etc/fcron/fcron.conf"
  10. fi
  11. getconfig() {
  12. local key="$1"
  13. local value_default="$2"
  14. local value=
  15. if service_started; then
  16. value="$(service_get_value "${key}")"
  17. fi
  18. if [ -z "${value}" ] && [ -r "${FCRON_CONFIGFILE}" ]; then
  19. value="$(sed -n -e 's:^'"${key}"'[ \t]*=[ \t]*::p' "${FCRON_CONFIGFILE}")"
  20. fi
  21. if [ -z "${value}" ]; then
  22. # Value not explicitly set in the configfile or configfile does not exist
  23. # or is not readable
  24. echo "${value_default}"
  25. else
  26. echo "${value}"
  27. fi
  28. return 0
  29. }
  30. depend() {
  31. config "${FCRON_CONFIGFILE}"
  32. use clock logger
  33. need hostname
  34. # provide the cron service if we are the main instance
  35. [ "${SVCNAME}" = "fcron" ] && provide cron
  36. }
  37. command="/usr/bin/fcron"
  38. command_args="${FCRON_OPTS} -c \"${FCRON_CONFIGFILE}\""
  39. start_stop_daemon_args=${FCRON_SSDARGS:-"--wait 1000"}
  40. pidfile="$(getconfig pidfile /run/fcron.pid)"
  41. fcrontabs="$(getconfig fcrontabs /var/spool/fcron)"
  42. fifofile="$(getconfig fifofile /run/fcron.fifo)"
  43. required_files="${FCRON_CONFIGFILE}"
  44. extra_started_commands="reload"
  45. reload() {
  46. start-stop-daemon --signal HUP --pidfile "${pidfile}"
  47. }
  48. start_pre() {
  49. if [ "${SVCNAME}" != "fcron" ]; then
  50. local _has_invalid_instance_cfg=0
  51. if [ "${pidfile}" = "/run/fcron.pid" ]; then
  52. eerror "You cannot use the same pidfile like the default instance!"
  53. eerror "Please adjust your 'pidfile' setting in '${FCRON_CONFIGFILE}'."
  54. _has_invalid_instance_cfg=1
  55. fi
  56. if [ "${fcrontabs}" = "/var/spool/fcron" ]; then
  57. eerror "You cannot use the same fcrontabs location like the default instance!"
  58. eerror "Please adjust your 'fcrontabs' setting in '${FCRON_CONFIGFILE}'."
  59. _has_invalid_instance_cfg=1
  60. fi
  61. if [ "${fifofile}" = "/run/fcron.fifo" ]; then
  62. eerror "You cannot use the same fifo file like the default instance!"
  63. eerror "Please adjust your 'fifofile' setting in '${FCRON_CONFIGFILE}'."
  64. _has_invalid_instance_cfg=1
  65. fi
  66. [ ${_has_invalid_instance_cfg} -ne 0 ] && return 1
  67. fi
  68. checkpath --file "${FCRON_CONFIGFILE}" --owner root:fcron --mode 0640
  69. if [ ! -d "${fcrontabs}" ]; then
  70. ebegin "Creating missing spooldir '${fcrontabs}'"
  71. ${command} --newspooldir "${fcrontabs}"
  72. eend $?
  73. fi
  74. }
  75. start_post() {
  76. service_set_value fcrontabs "${fcrontabs}"
  77. service_set_value fifofile "${fifofile}"
  78. }