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