Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: eva@g.o
Subject: Re: [gentoo-dev] [PATCH systemd.eclass] Introduce systemd_install_serviced().
Date: Sun, 08 Sep 2013 16:42:14
Message-Id: 20130908174628.277ebfaf@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH systemd.eclass] Introduce systemd_install_serviced(). by Gilles Dartiguelongue
1 Dnia 2013-09-08, o godz. 17:14:54
2 Gilles Dartiguelongue <eva@g.o> napisał(a):
3
4 > Le dimanche 08 septembre 2013 à 13:12 +0200, Michał Górny a écrit :
5 > > This function can be used to install service configuration templates.
6 > > Usage:
7 > >
8 > > systemd_install_serviced "${FILESDIR}"/foo.service.conf
9 > >
10 > > or:
11 > >
12 > > systemd_install_serviced "${FILESDIR}"/barbaz foo.service
13 > >
14 > > with the latter specifying related service name explicitly, former
15 > > expecting it to match ${basename%.conf}. The files are installed as:
16 > >
17 > > /etc/systemd/system/foo.service.d/00gentoo.conf
18 > >
19 > > They should be commented out templates that users can use to customize
20 > > the service easily.
21 >
22 > Looks like a good idea, do you have a few example packages where that
23 > could be used ?
24
25 Pacho answered this one for me ;).
26
27 > > ---
28 > > gx86/eclass/systemd.eclass | 26 ++++++++++++++++++++++++++
29 > > 1 file changed, 26 insertions(+)
30 > >
31 > > diff --git a/gx86/eclass/systemd.eclass b/gx86/eclass/systemd.eclass
32 > > index 4566631..1575b78 100644
33 > > --- a/gx86/eclass/systemd.eclass
34 > > +++ b/gx86/eclass/systemd.eclass
35 > > @@ -131,6 +131,32 @@ systemd_newunit() {
36 > > newins "${@}"
37 > > }
38 > >
39 > > +# @FUNCTION: systemd_install_serviced
40 > > +# @USAGE: <conf-file> [<service.d>]
41 > > +# @DESCRIPTION:
42 > > +# Install the file <conf-file> as service.d/00gentoo.conf template.
43 > > +# The <service.d> argument specifies the configured service name.
44 > > +# If not specified, the configuration file name will be used with .conf
45 > > +# suffix stripped (e.g. foo.service.conf -> foo.service).
46 > > +systemd_install_serviced() {
47 > > + debug-print-function ${FUNCNAME} "${@}"
48 > > +
49 > > + local src=${1}
50 > > + local service=${2}
51 > > +
52 > > + if [[ ! ${service} ]]; then
53 > > + [[ ${src} == *.conf ]] || die "Source file needs .conf suffix"
54 > > + service=${src##*/}
55 > > + service=${service%.conf}
56 > > + fi
57 > > + # avoid potentially common mistake
58 > > + [[ ${service} != *.d ]] || die "Service must not have .d suffix"
59 > > +
60 > > + local INSDESTTREE
61 >
62 > I guess this is a leftover ?
63
64 Nope. 'insinto' sets INSDESTTREE. Due to lack of proper scoping
65 support in bash, we need to localize this variable to restore previous
66 'insinto' scope after leaving the function.
67
68 > > + insinto /etc/systemd/system/"${service}".d
69 > > + newins "${src}" 00gentoo.conf
70 > > +}
71 > > +
72 > > # @FUNCTION: systemd_dotmpfilesd
73 > > # @USAGE: tmpfilesd1 [...]
74 > > # @DESCRIPTION:
75
76 --
77 Best regards,
78 Michał Górny

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies