diff options
| author | Otavio Salvador <otavio@ossystems.com.br> | 2011-11-04 17:25:59 +0000 |
|---|---|---|
| committer | Koen Kooi <koen@dominion.thruhere.net> | 2011-11-04 19:41:19 +0100 |
| commit | 39ce6e1fbba636b21f635ac9aa3c3155e259fb6c (patch) | |
| tree | 8d15d8471c600bb08b02628ec1177d638a00499a | |
| parent | 79f35231a351a7df30db8b2037f274a41e8d9e58 (diff) | |
| download | meta-openembedded-39ce6e1fbba636b21f635ac9aa3c3155e259fb6c.tar.gz | |
systemd.bbclass: make easier handle service enabling
This generates the postinst/prerm/postrm routines for the package
specified in SYSTEMD_PACKAGES avoding code duplication and
centralizing the handling of it for easy maintainence work.
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
Signed-off-by: Koen Kooi <koen@dominion.thruhere.net>
| -rw-r--r-- | meta-oe/classes/systemd.bbclass | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/meta-oe/classes/systemd.bbclass b/meta-oe/classes/systemd.bbclass new file mode 100644 index 0000000000..83833db6c7 --- /dev/null +++ b/meta-oe/classes/systemd.bbclass | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | SYSTEMDPN ?= "${PN}" | ||
| 2 | |||
| 3 | DEPENDS_append = " systemd-systemctl-native" | ||
| 4 | RDEPENDS_${SYSTEMDPN}_append = " systemd" | ||
| 5 | |||
| 6 | systemd_postinst() { | ||
| 7 | OPTS="" | ||
| 8 | |||
| 9 | if [ -n "$D" ]; then | ||
| 10 | OPTS="--root=$D" | ||
| 11 | fi | ||
| 12 | |||
| 13 | systemctl $OPTS enable ${SYSTEMD_SERVICE} | ||
| 14 | |||
| 15 | if [ -z "$D" ]; then | ||
| 16 | systemctl start ${SYSTEMD_SERVICE} | ||
| 17 | fi | ||
| 18 | } | ||
| 19 | |||
| 20 | systemd_prerm() { | ||
| 21 | if [ -z "$D" ]; then | ||
| 22 | systemctl stop ${SYSTEMD_SERVICE} | ||
| 23 | fi | ||
| 24 | } | ||
| 25 | |||
| 26 | systemd_postrm() { | ||
| 27 | systemctl disable ${SYSTEMD_SERVICE} | ||
| 28 | } | ||
| 29 | |||
| 30 | def systemd_after_parse(d): | ||
| 31 | if bb.data.getVar('SYSTEMD_PACKAGES', d) == None: | ||
| 32 | if bb.data.getVar('SYSTEMD_SERVICE', d) == None: | ||
| 33 | raise bb.build.FuncFailed, "%s inherits systemd but doesn't set SYSTEMD_SERVICE" % bb.data.getVar('FILE', d) | ||
| 34 | |||
| 35 | python __anonymous() { | ||
| 36 | systemd_after_parse(d) | ||
| 37 | } | ||
| 38 | |||
| 39 | python populate_packages_prepend () { | ||
| 40 | def systemd_package(pkg): | ||
| 41 | bb.debug(1, 'adding systemd calls to postinst/postrm for %s' % pkg) | ||
| 42 | localdata = bb.data.createCopy(d) | ||
| 43 | overrides = bb.data.getVar("OVERRIDES", localdata, 1) | ||
| 44 | bb.data.setVar("OVERRIDES", "%s:%s" % (pkg, overrides), localdata) | ||
| 45 | bb.data.update_data(localdata) | ||
| 46 | |||
| 47 | """ | ||
| 48 | systemd postinst is appended here because pkg_postinst may require to | ||
| 49 | execute on the target. Not doing so may cause systemd postinst invoked | ||
| 50 | twice to cause unwanted warnings. | ||
| 51 | """ | ||
| 52 | postinst = bb.data.getVar('pkg_postinst', localdata, 1) | ||
| 53 | if not postinst: | ||
| 54 | postinst = '#!/bin/sh\n' | ||
| 55 | postinst += bb.data.getVar('systemd_postinst', localdata, 1) | ||
| 56 | bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d) | ||
| 57 | |||
| 58 | prerm = bb.data.getVar('pkg_prerm', localdata, 1) | ||
| 59 | if not prerm: | ||
| 60 | prerm = '#!/bin/sh\n' | ||
| 61 | prerm += bb.data.getVar('systemd_prerm', localdata, 1) | ||
| 62 | bb.data.setVar('pkg_prerm_%s' % pkg, prerm, d) | ||
| 63 | |||
| 64 | postrm = bb.data.getVar('pkg_postrm', localdata, 1) | ||
| 65 | if not postrm: | ||
| 66 | postrm = '#!/bin/sh\n' | ||
| 67 | postrm += bb.data.getVar('systemd_postrm', localdata, 1) | ||
| 68 | bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d) | ||
| 69 | |||
| 70 | pkgs = bb.data.getVar('SYSTEMD_PACKAGES', d, 1) | ||
| 71 | if pkgs == None: | ||
| 72 | pkgs = bb.data.getVar('SYSTEMDPN', d, 1) | ||
| 73 | packages = (bb.data.getVar('PACKAGES', d, 1) or "").split() | ||
| 74 | if not pkgs in packages and packages != []: | ||
| 75 | pkgs = packages[0] | ||
| 76 | for pkg in pkgs.split(): | ||
| 77 | systemd_package(pkg) | ||
| 78 | } | ||
