s6.eclass 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: s6.eclass
  4. # @MAINTAINER:
  5. # William Hubbs <williamh@gentoo.org>
  6. # @BLURB: helper functions to install s6 services
  7. # @DESCRIPTION:
  8. # This eclass provides helpers to install s6 services.
  9. # @EXAMPLE:
  10. #
  11. # @CODE
  12. # inherit s6
  13. #
  14. # src_install() {
  15. # ...
  16. # s6_install_service myservice "${FILESDIR}"/run-s6 "${FILESDIR}"/finish-s6
  17. # ...
  18. # If you want a service to be logged, install the log service as
  19. # shown here.
  20. # s6_install_service myservice/log "${FILESDIR}"/log-run-s6 \
  21. # "${FILESDIR}"/log-finish-s6
  22. # ...
  23. # }
  24. # @CODE
  25. case ${EAPI:-0} in
  26. 5|6) ;;
  27. *) die "${ECLASS}.eclass: API in EAPI ${EAPI} not yet established" ;;
  28. esac
  29. # @FUNCTION: _s6_get_servicedir
  30. # @INTERNAL
  31. # @DESCRIPTION:
  32. # Get unprefixed servicedir.
  33. _s6_get_servicedir() {
  34. echo /var/svc.d
  35. }
  36. # @FUNCTION: s6_get_servicedir
  37. # @DESCRIPTION:
  38. # Output the path for the s6 service directory (not including ${D}).
  39. s6_get_servicedir() {
  40. debug-print-function ${FUNCNAME} "${@}"
  41. echo "${EPREFIX}$(_s6_get_servicedir)"
  42. }
  43. # @FUNCTION: s6_install_service
  44. # @USAGE: servicename run finish
  45. # @DESCRIPTION:
  46. # Install an s6 service.
  47. # servicename is the name of the service.
  48. # run is the run script for the service.
  49. # finish is the optional finish script for the service.
  50. s6_install_service() {
  51. debug-print-function ${FUNCNAME} "${@}"
  52. local name="$1"
  53. local run="$2"
  54. local finish="$3"
  55. [[ $name ]] ||
  56. die "${ECLASS}.eclass: you must specify the s6 service name"
  57. [[ $run ]] ||
  58. die "${ECLASS}.eclass: you must specify the s6 service run script"
  59. (
  60. local servicepath="$(_s6_get_servicedir)/$name"
  61. exeinto "$servicepath"
  62. newexe "$run" run
  63. [[ $finish ]] && newexe "$finish" finish
  64. )
  65. }
  66. # @FUNCTION: s6_service_down
  67. # @USAGE: servicename
  68. # @DESCRIPTION:
  69. # Install the "down" flag so this service will not be started by
  70. # default.
  71. # servicename is the name of the service.
  72. s6_service_down() {
  73. debug-print-function ${FUNCNAME} "${@}"
  74. local name="$1"
  75. [[ $name ]] ||
  76. die "${ECLASS}.eclass: you must specify the s6 service name"
  77. (
  78. touch "$T"/down || die
  79. local servicepath="$(_s6_get_servicedir)/$name"
  80. insinto "$servicepath"
  81. doins "$T"/down
  82. )
  83. }
  84. # @FUNCTION: s6_service_nosetsid
  85. # @USAGE: servicename
  86. # @DESCRIPTION:
  87. # Install the "nosetsid" flag so this service will not be made a session
  88. # leader.
  89. # servicename is the name of the service.
  90. s6_service_nosetsid() {
  91. debug-print-function ${FUNCNAME} "${@}"
  92. local name="$1"
  93. [[ $name ]] ||
  94. die "${ECLASS}.eclass: you must specify the s6 service name"
  95. (
  96. touch "$T"/nosetsid || die
  97. local servicepath="$(_s6_get_servicedir)/$name"
  98. insinto "$servicepath"
  99. doins "$T"/nosetsid
  100. )
  101. }