Skip to contentSkip to conversation

systemd-systemctl-native: add multiple services support

PATCH Superseded Andreas Müller 3 participants 36 messages Feb 11, 2012 – Feb 15, 2012

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 systemd-systemctl-native: add multiple services support

Thanks to Otavio Salvador for helping hint [1]

[1] http://lists.linuxtogo.org/pipermail/openembedded-devel/2012-February/037856.html

---
 .../systemd/systemd-systemctl-native/systemctl     |   75 +++++++++++---------
 1 files changed, 42 insertions(+), 33 deletions(-)
meta-oe/recipes-core/systemd/systemd-systemctl-native/systemctl +42 -33
index 54c1a18..72b9da3 100755
@@ -10,50 +10,59 @@ while [ $# != 0 ]; do
 		enable)
 			shift
 
-			service="$1"
+			services="$1"
+			in_enable="1"
 			shift
 			;;
 		--root=*)
 			ROOT=${opt##--root=}
+			in_enable="0"
 			shift
 			;;
 		*)
-			echo "'$opt' is an unkown option; exiting with error"
-			exit 1
+			if [ "$in_enable" = "1" ]; then
+				services="$services $opt" 
+				shift
+			else
+				echo "'$opt' is an unkown option; exiting with error"
+				exit 1
+			fi
 			;;
 	esac
 done
 
-# find service file
-for p in $ROOT/etc/systemd/system \
-         $ROOT/lib/systemd/system \
-         $ROOT/usr/lib/systemd/system; do
-	if [ -e $p/$service ]; then
-		service_file=$p/$service
-		service_file=${service_file##$ROOT}
+for service in "$services"; do
+	# find service file
+	for p in $ROOT/etc/systemd/system \
+		 $ROOT/lib/systemd/system \
+		 $ROOT/usr/lib/systemd/system; do
+		if [ -e $p/$service ]; then
+			service_file=$p/$service
+			service_file=${service_file##$ROOT}
+		fi
+	done
+	if [ -z "$service_file" ]; then
+		echo "'$service' couldn't be found; exiting with error"
+		exit 1
 	fi
-done
-if [ -z "$service_file" ]; then
-	echo "'$service' couldn't be found; exiting with error"
-	exit 1
-fi
-
-# create the required symbolic links
-wanted_by=$(grep WantedBy $ROOT/$service_file \
-                | sed 's,WantedBy=,,g' \
-                | tr ',' '\n' \
-                | grep '\.target$')
-
-for r in $wanted_by; do
-	mkdir -p $ROOT/etc/systemd/system/$r.wants
-	ln -s $service_file $ROOT/etc/systemd/system/$r.wants
-	echo "Enabled $service for $wanted_by."
-done
 
-# call us for the other required scripts
-also=$(grep Also $ROOT/$service_file \
-           | sed 's,Also=,,g' \
-           | tr ',' '\n')
-for a in $also; do
-	$0 --root=$ROOT enable $a
+	# create the required symbolic links
+	wanted_by=$(grep WantedBy $ROOT/$service_file \
+		        | sed 's,WantedBy=,,g' \
+		        | tr ',' '\n' \
+		        | grep '\.target$')
+
+	for r in $wanted_by; do
+		mkdir -p $ROOT/etc/systemd/system/$r.wants
+		ln -s $service_file $ROOT/etc/systemd/system/$r.wants
+		echo "Enabled $service for $wanted_by."
+	done
+
+	# call us for the other required scripts
+	also=$(grep Also $ROOT/$service_file \
+		   | sed 's,Also=,,g' \
+		   | tr ',' '\n')
+	for a in $also; do
+		$0 --root=$ROOT enable $a
+	done
 done
Signature · 1 line
1.7.4.4
#1 lore raw

PATCH 2/7 systemd.bbclass: enhance checks for SYSTEMD_PACKAGES and SYSTEMD_SERVICE

after recipe parsing the following plausibilities are checked:
* ERROR if empty SYSTEMD_PACKAGES
* ERROR if SYSTEMD_PACKAGES entry does not contain '-systemd' AND package_name != ${PN}
* ERROR if SYSTEMD_PACKAGES entry contains '-systemd' but entry without '-systemd' (base pkg) does not exist
* WARNING if SYSTEMD_PACKAGES containing ${PN} to force package maintainers to split out systemd-specific files into *-systemd
* error if SYSTEMD_SERVICE(_<systemd-package>) is empty for one or more entries in SYSTEMD_PACKAGES

The code in populate_packages_prepend to set SYSTEMD_PACKAGES to ${PN} as default was removed.

---
 meta-oe/classes/systemd.bbclass |   43 +++++++++++++++++++++++++++++++-------
 1 files changed, 35 insertions(+), 8 deletions(-)
meta-oe/classes/systemd.bbclass +35 -8
index 094a12c..bc83908 100644
@@ -25,9 +25,41 @@ systemctl disable ${SYSTEMD_SERVICE}
 }
 
 def systemd_after_parse(d):
-    if bb.data.getVar('SYSTEMD_PACKAGES', d) == None:
-        if bb.data.getVar('SYSTEMD_SERVICE', d) == None:
-            raise bb.build.FuncFailed, "%s inherits systemd but doesn't set SYSTEMD_SERVICE" % bb.data.getVar('FILE', d)
+	def systemd_check_vars():
+		# not for native / only at parse time
+		if d.getVar('BPN', 1) + "-native" != d.getVar('PN', 1) and d.getVar('BB_WORKERCONTEXT', True) is None:
+			bb_filename = d.getVar('FILE')
+			packages = d.getVar('PACKAGES', 1)
+
+			# check SYSTEMD_PACKAGES
+			systemd_pkgs = d.getVar('SYSTEMD_PACKAGES', 1) or ""
+			if systemd_pkgs == "":
+				raise bb.build.FuncFailed, "\n\n%s inherits systemd but doesn't set SYSTEMD_PACKAGES" % bb_filename
+			for pkg_systemd in systemd_pkgs.split():
+				if pkg_systemd.find("-systemd") == -1:
+					if pkg_systemd != d.getVar('PN', 1):
+						raise bb.build.FuncFailed, \
+							"\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN} (deprecated)" % \
+							(bb_filename, pkg_systemd)
+					else:
+						bb.warn("%s: it is recommended to set SYSTEMD_PACKAGES as <existing-package>-systemd" % bb_filename)
+				else:
+					pkg_systemd_base = pkg_systemd.replace('-systemd', '')
+					if pkg_systemd_base not in packages:
+						raise bb.build.FuncFailed, \
+							"\n\n%s: %s in SYSTEMD_PACKAGES does not match <existing-package>-systemd or ${PN} (deprecated)" % \
+							( bb_filename, pkg_systemd)
+
+			# check SYSTEMD_SERVICE
+			for pkg_systemd in systemd_pkgs.split():
+				service_pkg = 'SYSTEMD_SERVICE' + "_" + pkg_systemd
+				systemd_services = d.getVar(service_pkg, 1) or d.getVar('SYSTEMD_SERVICE', 1) or ""
+				if systemd_services == "":
+					raise bb.build.FuncFailed, "\n\n%s inherits systemd but doesn't set SYSTEMD_SERVICE / %s" % (bb_filename, service_pkg)
+
+
+	systemd_check_vars()
+
 
 python __anonymous() {
     systemd_after_parse(d)
@@ -70,11 +102,6 @@ python populate_packages_prepend () {
 
 
 	pkgs = bb.data.getVar('SYSTEMD_PACKAGES', d, 1)
-	if pkgs == None:
-		pkgs = bb.data.getVar('PN', d, 1)
-		packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
-		if not pkgs in packages and packages != []:
-			pkgs = packages[0]
 	for pkg in pkgs.split():
 		systemd_package(pkg)
 }
Signature · 1 line
1.7.4.4
#2 lore raw

Re: [meta-oe 2/7] systemd.bbclass: enhance checks for SYSTEMD_PACKAGES and SYSTEMD_SERVICE

meta-oe/classes/systemd.bbclass systemctl disable ${SYSTEMD_SERVICE} · line 29

Quoted 3 lines · Andreas Müller
meta-oe/classes/systemd.bbclass +2 -0
+       def systemd_check_vars():
+               # not for native / only at parse time

Doesn't it need to take into account for cross and nativesdk too?

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#3 lore raw

Re: [meta-oe 2/7] systemd.bbclass: enhance checks for SYSTEMD_PACKAGES and SYSTEMD_SERVICE

Quoted 9 lines · Otavio Salvador
Quoted 3 lines · Andreas Müller

+       def systemd_check_vars():
+               # not for native / only at parse time

Doesn't it need to take into account for cross and nativesdk too?

Currently there is no case for this. Since I see no harm adding cross and nativesdk I will extend in V2.

Andreas

#4 lore raw

PATCH 3/7 systemd.bbclass: cosmetics

In reply to Andreas Müller
---
 meta-oe/classes/systemd.bbclass |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)
meta-oe/classes/systemd.bbclass +7 -8
index bc83908..7ec4ca4 100644
@@ -66,7 +66,7 @@ python __anonymous() {
 }
 
 python populate_packages_prepend () {
-	def systemd_package(pkg):
+	def systemd_prepost_instrm(pkg):
 		bb.debug(1, 'adding systemd calls to postinst/postrm for %s' % pkg)
 		localdata = bb.data.createCopy(d)
 		overrides = bb.data.getVar("OVERRIDES", localdata, 1)
@@ -90,10 +90,10 @@ python populate_packages_prepend () {
 		prerm += bb.data.getVar('systemd_prerm', localdata, 1)
 		bb.data.setVar('pkg_prerm_%s' % pkg, prerm, d)
 
-	        postrm = bb.data.getVar('pkg_postrm', localdata, 1)
-	        if not postrm:
-	                postrm = '#!/bin/sh\n'
-                postrm += bb.data.getVar('systemd_postrm', localdata, 1)
+		postrm = bb.data.getVar('pkg_postrm', localdata, 1)
+		if not postrm:
+			postrm = '#!/bin/sh\n'
+		postrm += bb.data.getVar('systemd_postrm', localdata, 1)
 		bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d)
 
 		rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "")
@@ -101,7 +101,6 @@ python populate_packages_prepend () {
 		bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
 
 
-	pkgs = bb.data.getVar('SYSTEMD_PACKAGES', d, 1)
-	for pkg in pkgs.split():
-		systemd_package(pkg)
+	for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split():
+		systemd_prepost_instrm(pkg_systemd)
 }
Signature · 1 line
1.7.4.4
#5 lore raw

Re: [meta-oe 3/7] systemd.bbclass: cosmetics

meta-oe/classes/systemd.bbclass python __anonymous() { · line 69

Quoted 4 lines · Andreas Müller

python populate_packages_prepend () {

meta-oe/classes/systemd.bbclass +1 -1
-       def systemd_package(pkg):
+       def systemd_prepost_instrm(pkg):

I fully agree about renaming it but wouldn't systemd_generate_package_scripts(pkg) be more descriptive?

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#6 lore raw

Re: [meta-oe 3/7] systemd.bbclass: cosmetics

Quoted 11 lines · Otavio Salvador
Quoted 4 lines · Andreas Müller

 python populate_packages_prepend () {
-       def systemd_package(pkg):
+       def systemd_prepost_instrm(pkg):

I fully agree about renaming it but wouldn't systemd_generate_package_scripts(pkg) be more descriptive?

V2 will get that

Andreas

#7 lore raw

PATCH 4/7 systemd.bbclass: automatically create packages set in SYSTEMD_PACKAGES

In reply to Andreas Müller
---
 meta-oe/classes/systemd.bbclass |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
meta-oe/classes/systemd.bbclass +9 -0
index 7ec4ca4..ffcabe9 100644
@@ -57,8 +57,17 @@ def systemd_after_parse(d):
 				if systemd_services == "":
 					raise bb.build.FuncFailed, "\n\n%s inherits systemd but doesn't set SYSTEMD_SERVICE / %s" % (bb_filename, service_pkg)
 
+	# prepend systemd-packages not already included
+	def systemd_create_package(pkg_systemd):
+		packages = d.getVar('PACKAGES', 1)
+		if not pkg_systemd in packages:
+			packages = "%s %s" % (pkg_systemd, packages)
+			d.setVar('PACKAGES', packages)
+
 
 	systemd_check_vars()
+	for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split():
+		systemd_create_package(pkg_systemd)
 
 
 python __anonymous() {
Signature · 1 line
1.7.4.4
Acked-by on v1 4/7
#8 lore raw

Re: [meta-oe 4/7] systemd.bbclass: automatically create packages set in SYSTEMD_PACKAGES

Quoted 40 lines · Andreas Müller
---
 meta-oe/classes/systemd.bbclass |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
meta-oe/classes/systemd.bbclass +9 -0
index 7ec4ca4..ffcabe9 100644
@@ -57,8 +57,17 @@ def systemd_after_parse(d):
                               if systemd_services == "":
                                       raise bb.build.FuncFailed, "\n\n%s
 inherits systemd but doesn't set SYSTEMD_SERVICE / %s" % (bb_filename,
 service_pkg)
 
+       # prepend systemd-packages not already included
+       def systemd_create_package(pkg_systemd):
+               packages = d.getVar('PACKAGES', 1)
+               if not pkg_systemd in packages:
+                       packages = "%s %s" % (pkg_systemd, packages)
+                       d.setVar('PACKAGES', packages)
+
 
       systemd_check_vars()
+       for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split():
+               systemd_create_package(pkg_systemd)
 

python __anonymous() {
--
1.7.4.4

_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#9 lore raw

PATCH 5/7 automatically install all *.service and *.socket supplied in recipe's SRC_URI

In reply to Andreas Müller
---
 meta-oe/classes/systemd.bbclass |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
meta-oe/classes/systemd.bbclass +11 -0
index ffcabe9..3c1ed14 100644
@@ -74,6 +74,17 @@ python __anonymous() {
     systemd_after_parse(d)
 }
 
+# automatically install all *.service and *.socket supplied in recipe's SRC_URI
+do_install_append() {
+    install -d ${D}${base_libdir}/systemd/system
+    for service in `find ${WORKDIR} -maxdepth 1 -name '*.service' -o -name '*.socket'` ; do
+	# ensure installing systemd-files only (e.g not avahi *.service)
+	if grep -q '\[Unit\]' $service ; then
+	        install -m 644 $service ${D}${base_libdir}/systemd/system
+	fi
+    done
+}
+
 python populate_packages_prepend () {
 	def systemd_prepost_instrm(pkg):
 		bb.debug(1, 'adding systemd calls to postinst/postrm for %s' % pkg)
Signature · 1 line
1.7.4.4
Acked-by on v1 5/7
#10 lore raw

Re: [meta-oe 5/7] automatically install all *.service and *.socket supplied in recipe's SRC_URI

Quoted 41 lines · Andreas Müller
---
 meta-oe/classes/systemd.bbclass |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
meta-oe/classes/systemd.bbclass +1 -0
index ffcabe9..3c1ed14 100644
@@ -74,6 +74,17 @@ python __anonymous() {
    systemd_after_parse(d)
 }
 
+# automatically install all *.service and *.socket supplied in recipe's

SRC_URI

meta-oe/classes/systemd.bbclass +10 -1
+do_install_append() {
+    install -d ${D}${base_libdir}/systemd/system
+    for service in `find ${WORKDIR} -maxdepth 1 -name '*.service' -o
-name '*.socket'` ; do
+       # ensure installing systemd-files only (e.g not avahi *.service)
+       if grep -q '\[Unit\]' $service ; then
+               install -m 644 $service ${D}${base_libdir}/systemd/system
+       fi
+    done
+}
+
 python populate_packages_prepend () {
       def systemd_prepost_instrm(pkg):
               bb.debug(1, 'adding systemd calls to postinst/postrm for

%s' % pkg)
--
1.7.4.4

_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#11 lore raw

PATCH 6/7 systemd.bbclass: automatically extend FILES_* for systemd packages

In reply to Andreas Müller

In case SYSTEMD_SERVICE contains only one *.service file, the whole folder ${base_libdir}/systemd/system/ is added to FILES_* otherwise only the *.service files found in SYSTEMD_SERVICE.

---
 meta-oe/classes/systemd.bbclass |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
meta-oe/classes/systemd.bbclass +16 -0
index 3c1ed14..8927980 100644
@@ -120,7 +120,23 @@ python populate_packages_prepend () {
 		rdepends.append("systemd")
 		bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
 
+	# add systemd files to FILES_*-systemd
+	def systemd_add_files(pkg_systemd):
+		systemd_services = d.getVar('SYSTEMD_SERVICE' + "_" + pkg_systemd, 1) or d.getVar('SYSTEMD_SERVICE', 1)
+		files_append = ""
+		if len(systemd_services.split()) == 1:
+			# distribute complete ${base_libdir}/systemd/system/ to ${SYSTEMD_PACKAGES}
+			files_append = '${base_libdir}/systemd/system/'
+		else:
+			# distribute files set in SYSTEMD_SERVICE to ${SYSTEMD_PACKAGES}
+			for service in systemd_services.split():
+				files_append += ' ${base_libdir}/systemd/system/' + service
+
+		var_name = "FILES_" + pkg_systemd
+		files = d.getVar(var_name, 0) or ""
+		d.setVar(var_name, "%s %s" % (files, files_append))
 
 	for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split():
 		systemd_prepost_instrm(pkg_systemd)
+		systemd_add_files(pkg_systemd)
 }
Signature · 1 line
1.7.4.4
#12 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 5 lines · Andreas Müller

In case SYSTEMD_SERVICE contains only one *.service file, the whole folder ${base_libdir}/systemd/system/ is added to FILES_* otherwise only the *.service
files found in SYSTEMD_SERVICE.

It seems you'll need to parse the service file and check if it installs others. For example .socket files usually do that. And then you'll never add the whole dir automatically but dependently of the services it needs to install.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#13 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 8 lines · Otavio Salvador
Quoted 5 lines · Andreas Müller

In case SYSTEMD_SERVICE contains only one *.service file, the whole folder ${base_libdir}/systemd/system/ is added to FILES_* otherwise only the *.service
files found in SYSTEMD_SERVICE.

Off topic: My intention was to install the whole directory for recipes with one service per package AND one *-systemd package (this case is not catched by my code - so there will be a V2)

Quoted 6 lines

It seems you'll need to parse the service file and check if it installs others. For example .socket files usually do that. And then you'll never add the whole dir automatically but dependently of the services it needs to install.

I am afraid this goes a bit to far and causes confusion what is packed. I would prefer the simple rule:

If there is one *-systemd package with one entry in SYSTEMD_SERVICE, the whole directory is installed - otherwise only the files found in SYSTEMD_SERVICE. If a recipe installs too much or something is missing, it can be corrected in recipe.

What is common opinion here?

Andreas

#14 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 5 lines · Andreas Müller

If there is one *-systemd package with one entry in SYSTEMD_SERVICE, the whole directory is installed - otherwise only the files found in SYSTEMD_SERVICE. If a recipe installs too much or something is missing, it can be corrected in recipe.

If for example I put two .socket files, your algorithm will break. That's why I said you need to parse it. It is not that difficult as the logic is the same as the wrapper used in rootfs generation.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#15 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 9 lines · Otavio Salvador
Quoted 5 lines · Andreas Müller

If there is one *-systemd package with one entry in SYSTEMD_SERVICE, the whole directory is installed - otherwise only the files found in SYSTEMD_SERVICE. If a recipe installs too much or something is missing, it can be corrected in recipe.

Quoted 3 lines

If for example I put two .socket files, your algorithm will break. That's why I said you need to parse it. It is not that difficult as the logic is the same as the wrapper used in rootfs generation.

Sorry - but which which wrapper do you mean?

Andreas

#16 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 4 lines · Andreas Müller
Quoted 3 lines

If for example I put two .socket files, your algorithm will break. That's why I said you need to parse it. It is not that difficult as the logic is the same as the wrapper used in rootfs generation.

Sorry - but which which wrapper do you mean?

systemd-systemctl-native

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#17 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 10 lines · Otavio Salvador
Quoted 4 lines · Andreas Müller
Quoted 3 lines

If for example I put two .socket files, your algorithm will break. That's why I said you need to parse it. It is not that difficult as the logic is the same as the wrapper used in rootfs generation.

Sorry - but which which wrapper do you mean?

systemd-systemctl-native

Off list @Otavio: not boring but challenging...

To reuse as much as possible: Is there a piece of code showing me how to mix up shell/python code?

Andreas

#18 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 5 lines · Andreas Müller
Quoted 1 line

systemd-systemctl-native

Off list @Otavio: not boring but challenging...

To reuse as much as possible: Is there a piece of code showing me how to mix up shell/python code?

Not that I am aware of but you can look at combo-layer script how to read and parse ini files; this ought to be very simple to do.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#19 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 4 lines · Otavio Salvador
Quoted 1 line · Andreas Müller
Quoted 1 line

systemd-systemctl-native

Quoted 9 lines
Quoted 4 lines

Off list @Otavio: not boring but challenging...

To reuse as much as possible: Is there a piece of code showing me how to mix up shell/python code?

Not that I am aware of but you can look at combo-layer script how to read and parse ini files; this ought to be very simple to do.

Currently I am testing the automatic parsing for different recipes. Following the 'After=' and 'WantedBy=' works fine but before sending out I would like to get some comments on the following assumptions/questions:

* There is no need for recipes to install links for 'WantedBy' entries since systemd-systemctl-native takes care. E.G the code in lightttpd_1.4.30.bbappend for this can be removed (it works on the wrong paths anyway) -> there is no need for systemd.bbclass to follow 'WantedBy'. Correct?

* For dropbear_2011.54.bbappend, the automatic parsing leaves [email protected] and dropbear.service ( link to /dev/null ) unpacked. In dropbear.socket there is 'Conflicts=dropbear.service'. Shall the algorithm follow also services linked by Conflicts= and pack those service files?

* dropbear_2011.54.bbappend: Is [email protected] a candidate for a second *-systemd packet?

* are there other keys which might need follow-up too?

Thanks in advance

Andreas

#20 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 11 lines · Andreas Müller

Currently I am testing the automatic parsing for different recipes. Following the 'After=' and 'WantedBy=' works fine but before sending out I would like to get some comments on the following assumptions/questions:

* There is no need for recipes to install links for 'WantedBy' entries since systemd-systemctl-native takes care. E.G the code in lightttpd_1.4.30.bbappend for this can be removed (it works on the wrong paths anyway) -> there is no need for systemd.bbclass to follow 'WantedBy'. Correct?

Links ought to be kept to be handled by systemd-systemctl-native.

Quoted 6 lines

* For dropbear_2011.54.bbappend, the automatic parsing leaves [email protected] and dropbear.service ( link to /dev/null ) unpacked. In dropbear.socket there is 'Conflicts=dropbear.service'. Shall the algorithm follow also services linked by Conflicts= and pack those service files?

The /dev/null link is to force disable the init script. This is difficult to do automatically so for now I'd say to do it byhand.

Quoted 3 lines

* dropbear_2011.54.bbappend: Is [email protected] a candidate for a second *-systemd packet?

No; The @ is to allow multiple instance. Look at
http://www.freedesktop.org/software/systemd/man/systemd.unit.html

Quoted 2 lines

* are there other keys which might need follow-up too?

Not that I am aware of at this moment.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#22 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 7 lines · Andreas Müller
Quoted 2 lines · Otavio Salvador

No; The @ is to allow multiple instance. Look at
http://www.freedesktop.org/software/systemd/man/systemd.unit.html

How about the old strategy for *@.service:
If there is only one *-systemd package with one entry in SYSTEMD_SERVICE it will get *@.service?

I think so.

It is not easy to predict all possible usages but we ought to take this route and adjust it one the way. Once you do it and we start converting all recipes that use systemd class in meta-oe we'll most probably find many possible corner-cases to deal with.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#23 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 12 lines · Otavio Salvador
Quoted 7 lines · Andreas Müller
Quoted 2 lines · Otavio Salvador

No; The @ is to allow multiple instance. Look at
http://www.freedesktop.org/software/systemd/man/systemd.unit.html

How about the old strategy for *@.service:
If there is only one *-systemd package with one entry in SYSTEMD_SERVICE it will get *@.service?

Quoted 7 lines

I think so.

It is not easy to predict all possible usages but we ought to take this route and adjust it one the way. Once you do it and we start converting all recipes that use systemd class in meta-oe we'll most probably find many possible corner-cases to deal with.

Another corner case I would like to understand: What is the role of in busybox syslog.service linking to dev/null. Within busybox itself it seems not referenced.

Thanks in advance

Andreas

#24 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 4 lines · Andreas Müller

Another corner case I would like to understand: What is the role of in busybox syslog.service linking to dev/null. Within busybox itself it seems not referenced.

To make it to use the .service file and not the init scripts compatibility.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#25 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 10 lines · Otavio Salvador
Quoted 4 lines · Andreas Müller

Another corner case I would like to understand: What is the role of in busybox syslog.service linking to dev/null. Within busybox itself it seems not referenced.

To make it to use the .service file and not the init scripts compatibility.

For test I did with a bunch of recipes

1. build from scratch with unmodified sources
2. Applied sytemd-patches and the 'cleanup'-patches (removing obsolete systemd code in recipes)
3. build recipes again
4. compared the results with buildhistory

Results are as expected except one issue I don't understand:

The sizes of the *-dbg packages are reduced. Some reduce to less than half. Has anybody a good explanation for this?

Andreas

#26 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 8 lines · Andreas Müller

For test I did with a bunch of recipes

1. build from scratch with unmodified sources
2. Applied sytemd-patches and the 'cleanup'-patches (removing obsolete systemd code in recipes)
3. build recipes again
4. compared the results with buildhistory

Quoted 4 lines

Results are as expected except one issue I don't understand:

The sizes of the *-dbg packages are reduced. Some reduce to less than half. Has anybody a good explanation for this?

No good guess about possible reasoning.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#27 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 11 lines · Otavio Salvador
Quoted 8 lines · Andreas Müller

For test I did with a bunch of recipes

1. build from scratch with unmodified sources
2. Applied sytemd-patches and the 'cleanup'-patches (removing obsolete systemd code in recipes)
3. build recipes again
4. compared the results with buildhistory

Quoted 7 lines
Quoted 4 lines

Results are as expected except one issue I don't understand:

The sizes of the *-dbg packages are reduced. Some reduce to less than half. Has anybody a good explanation for this?

No good guess about possible reasoning.

Just guess:

-dbg packages contain also sources packaged for /usr/src/debug/, maybe your changes caused *.service files to be ommited from it?

Cheers,

Signature · 1 line
Martin 'JaMa' Jansa     jabber: [email protected]
#28 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

In reply to Otavio Salvador
Quoted 11 lines · Otavio Salvador
Quoted 8 lines · Andreas Müller

For test I did with a bunch of recipes

1. build from scratch with unmodified sources
2. Applied sytemd-patches and the 'cleanup'-patches (removing obsolete systemd code in recipes)
3. build recipes again
4. compared the results with buildhistory

Quoted 8 lines
Quoted 4 lines

Results are as expected except one issue I don't understand:

The sizes of the *-dbg packages are reduced. Some reduce to less than half. Has anybody a good explanation for this?

No good guess about possible reasoning.

I did further checks: seems many many source code files are missing (example - see attachment). Strange is that the value for FILES has not changed! What have done to cause that - or is this unrelated to my modifications?

Andreas

#29 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 19 lines · Andreas Müller
Quoted 17 lines · Otavio Salvador
Quoted 12 lines · Andreas Müller

For test I did with a bunch of recipes

1. build from scratch with unmodified sources
2. Applied sytemd-patches and the 'cleanup'-patches (removing obsolete systemd code in recipes)
3. build recipes again
4. compared the results with buildhistory

Results are as expected except one issue I don't understand:

The sizes of the *-dbg packages are reduced. Some reduce to less than half. Has anybody a good explanation for this?

Quoted 7 lines
Quoted 2 lines

No good guess about possible reasoning.

I did further checks: seems many many source code files are missing (example - see attachment). Strange is that the value for FILES has not changed!  What have done to cause that - or is this unrelated to my modifications?

*All* source files are missing. Which part of oe is responsible, packing these?

Andreas

#30 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 21 lines · Andreas Müller
Quoted 19 lines · Andreas Müller
Quoted 17 lines · Otavio Salvador
Quoted 12 lines · Andreas Müller

For test I did with a bunch of recipes

1. build from scratch with unmodified sources
2. Applied sytemd-patches and the 'cleanup'-patches (removing obsolete systemd code in recipes)
3. build recipes again
4. compared the results with buildhistory

Results are as expected except one issue I don't understand:

The sizes of the *-dbg packages are reduced. Some reduce to less than half. Has anybody a good explanation for this?

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

No good guess about possible reasoning.

I did further checks: seems many many source code files are missing (example - see attachment). Strange is that the value for FILES has not changed!  What have done to cause that - or is this unrelated to my modifications?

*All* source files are missing. Which part of oe is responsible, packing these?

OK I think this one unrelated to my changes. I did

* undo my patches
* bumped PR for poppler ( this one has no systemd 'contact' )
* build poppler

and for the bumped package

<..>/package/src/debug/

is empty!

Could somebody of you please do same and confirm?

Andreas

#31 lore raw

Re: [meta-oe 6/7] systemd.bbclass: automatically extend FILES_* for systemd packages

Quoted 1 line · Andreas Müller

<..>/package/src/debug/

of course this must be

<..>/package/usr/src/debug/

started a build from scratch with systemd patches...

Andreas

#32 lore raw

PATCH 7/7 systemd.bbclass: automatically extend RDEPENDS for *-systemd packages

In reply to Andreas Müller

* append systemd (functionalty moved into systemd_add_rdepends)
* append base-pgk

---
 meta-oe/classes/systemd.bbclass |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)
meta-oe/classes/systemd.bbclass +15 -4
index 8927980..edc2872 100644
@@ -116,10 +116,6 @@ python populate_packages_prepend () {
 		postrm += bb.data.getVar('systemd_postrm', localdata, 1)
 		bb.data.setVar('pkg_postrm_%s' % pkg, postrm, d)
 
-		rdepends = explode_deps(bb.data.getVar('RDEPENDS_' + pkg, d, 0) or bb.data.getVar('RDEPENDS', d, 0) or "")
-		rdepends.append("systemd")
-		bb.data.setVar('RDEPENDS_' + pkg, " " + " ".join(rdepends), d)
-
 	# add systemd files to FILES_*-systemd
 	def systemd_add_files(pkg_systemd):
 		systemd_services = d.getVar('SYSTEMD_SERVICE' + "_" + pkg_systemd, 1) or d.getVar('SYSTEMD_SERVICE', 1)
@@ -136,7 +132,22 @@ python populate_packages_prepend () {
 		files = d.getVar(var_name, 0) or ""
 		d.setVar(var_name, "%s %s" % (files, files_append))
 
+	# *-systemd packages get RDEPENDS to systemd and their base package
+	def systemd_add_rdepends(pkg_systemd):
+		pn_pkg = d.getVar('PN', 1)
+		# RDEPENDS_${pkg_systemd} += pkg_systemd_base systemd
+		rdepends = explode_deps(d.getVar('RDEPENDS_' + pkg_systemd, 1) or "")
+		if not 'systemd' in rdepends:
+			rdepends.append('systemd')
+		pkg_systemd_base = pkg_systemd.replace('-systemd', '')
+		# not rdepending myself / avoid double entries
+		if pkg_systemd != pn_pkg and not pkg_systemd_base in rdepends:
+			rdepends.append(pkg_systemd_base)
+		d.setVar('RDEPENDS_' + pkg_systemd, " " + " ".join(rdepends))
+
+
 	for pkg_systemd in d.getVar('SYSTEMD_PACKAGES', 1).split():
 		systemd_prepost_instrm(pkg_systemd)
 		systemd_add_files(pkg_systemd)
+		systemd_add_rdepends(pkg_systemd)
 }
Signature · 1 line
1.7.4.4
#33 lore raw

Re: [meta-oe 7/7] systemd.bbclass: automatically extend RDEPENDS for *-systemd packages

Quoted 3 lines · Andreas Müller

* append systemd (functionalty moved into systemd_add_rdepends)
* append base-pgk

This patch is OK but I think it would be nice if the recipe has it included in rdepends byhand we could do a warning saying it's use is deprecated so we can know about it and cleanup the recipes.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#34 lore raw

Re: [meta-oe 7/7] systemd.bbclass: automatically extend RDEPENDS for *-systemd packages

Quoted 11 lines · Otavio Salvador
Quoted 3 lines · Andreas Müller

* append systemd (functionalty moved into systemd_add_rdepends)
* append base-pgk

This patch is OK but I think it would be nice if the recipe has it included in rdepends byhand we could do a warning saying it's use is deprecated so we can know about it and cleanup the recipes.

good suggestion - V2 will have it

Andreas

Acked-by on v1 1/7
#35 lore raw
In reply to Andreas Müller
Quoted 121 lines · Andreas Müller

Thanks to Otavio Salvador for helping hint [1]

[1]
http://lists.linuxtogo.org/pipermail/openembedded-devel/2012-February/037856.html

---
 .../systemd/systemd-systemctl-native/systemctl     |   75
+++++++++++---------
 1 files changed, 42 insertions(+), 33 deletions(-)

diff --git a/meta-oe/recipes-core/systemd/systemd-systemctl-native/systemctl b/meta-oe/recipes-core/systemd/systemd-systemctl-native/systemctl index 54c1a18..72b9da3 100755

meta-oe/recipes-core/systemd/systemd-systemctl-native/systemctl +3 -2
@@ -10,50 +10,59 @@ while [ $# != 0 ]; do
               enable)
                       shift
 
-                       service="$1"
+                       services="$1"
+                       in_enable="1"
                       shift
                       ;;
               --root=*)
                       ROOT=${opt##--root=}
+                       in_enable="0"
                       shift
                       ;;
               *)
-                       echo "'$opt' is an unkown option; exiting with

error"

meta-oe/recipes-core/systemd/systemd-systemctl-native/systemctl +5 -1
-                       exit 1
+                       if [ "$in_enable" = "1" ]; then
+                               services="$services $opt"
+                               shift
+                       else
+                               echo "'$opt' is an unkown option; exiting

with error"

meta-oe/recipes-core/systemd/systemd-systemctl-native/systemctl +34 -31
+                               exit 1
+                       fi
                       ;;
       esac
 done
 
-# find service file
-for p in $ROOT/etc/systemd/system \
-         $ROOT/lib/systemd/system \
-         $ROOT/usr/lib/systemd/system; do
-       if [ -e $p/$service ]; then
-               service_file=$p/$service
-               service_file=${service_file##$ROOT}
+for service in "$services"; do
+       # find service file
+       for p in $ROOT/etc/systemd/system \
+                $ROOT/lib/systemd/system \
+                $ROOT/usr/lib/systemd/system; do
+               if [ -e $p/$service ]; then
+                       service_file=$p/$service
+                       service_file=${service_file##$ROOT}
+               fi
+       done
+       if [ -z "$service_file" ]; then
+               echo "'$service' couldn't be found; exiting with error"
+               exit 1
       fi
-done
-if [ -z "$service_file" ]; then
-       echo "'$service' couldn't be found; exiting with error"
-       exit 1
-fi
-
-# create the required symbolic links
-wanted_by=$(grep WantedBy $ROOT/$service_file \
-                | sed 's,WantedBy=,,g' \
-                | tr ',' '\n' \
-                | grep '\.target$')
-
-for r in $wanted_by; do
-       mkdir -p $ROOT/etc/systemd/system/$r.wants
-       ln -s $service_file $ROOT/etc/systemd/system/$r.wants
-       echo "Enabled $service for $wanted_by."
-done
 
-# call us for the other required scripts
-also=$(grep Also $ROOT/$service_file \
-           | sed 's,Also=,,g' \
-           | tr ',' '\n')
-for a in $also; do
-       $0 --root=$ROOT enable $a
+       # create the required symbolic links
+       wanted_by=$(grep WantedBy $ROOT/$service_file \
+                       | sed 's,WantedBy=,,g' \
+                       | tr ',' '\n' \
+                       | grep '\.target$')
+
+       for r in $wanted_by; do
+               mkdir -p $ROOT/etc/systemd/system/$r.wants
+               ln -s $service_file $ROOT/etc/systemd/system/$r.wants
+               echo "Enabled $service for $wanted_by."
+       done
+
+       # call us for the other required scripts
+       also=$(grep Also $ROOT/$service_file \
+                  | sed 's,Also=,,g' \
+                  | tr ',' '\n')
+       for a in $also; do
+               $0 --root=$ROOT enable $a
+       done
 done
--

1.7.4.4

_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br