All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] systemd patches
@ 2019-01-02 16:11 Jonas Bonn
  2019-01-02 16:11 ` [PATCH v2 1/5] systemd: do not create machine-id Jonas Bonn
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Jonas Bonn @ 2019-01-02 16:11 UTC (permalink / raw)
  To: openembedded-core

Changed in v2:
- address patchtest warnings:
  - include sign-offs on patches
  - include License-Update tag on patch that makes licensing change
- dropped patch implementing brute-force removal of unit files installed
  by systemd into /etc
- reworked the systemd-conf patch to restore the installation of the
  base systemd configuration files


**********

These patches make some modifications to systemd with the long-term goal
of being able to run OE in systemd's "stateless" configuration.
"Stateless" boils down to building an image with empty /etc and /var
directories so that volatile (tmpfs) filesystems can be mounted there;
this requires that the system subsequently be able to populate these
directories dynamically, which systemd mostly takes care of if things
are done right.

In these patches:
i)    Don't include machine-id in writable images so that systemd can run
its first-boot machinery
ii)   Move systemd configuration files out of /etc
iii)  Allow systemd to dynamically enable services and populate
/etc/systemd/system via the presets mechanism

There's a long way to go to get to a working "stateless" configuration.
Getting to a "volatile" system (just empty /var) should be easier and
I'll post patches moving things in that direction shortly.

/Jonas

Jonas Bonn (5):
  systemd: do not create machine-id
  systemd-conf: simplify creation of machine-specific configuration
  systemd: create preset files instead of installing in image
  systemd-systemctl-native: simplify and support preset-all
  rootfs-postcommands: call preset-all for read-only-rootfs

 meta/classes/rootfs-postcommands.bbclass      |  8 +++
 meta/classes/systemd.bbclass                  | 33 ++++++------
 meta/recipes-core/systemd/systemd-conf.bb     | 53 ++++++++-----------
 .../systemd/systemd-systemctl/systemctl       | 36 +++----------
 meta/recipes-core/systemd/systemd_239.bb      | 17 +++---
 5 files changed, 62 insertions(+), 85 deletions(-)

-- 
2.19.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/5] systemd: do not create machine-id
  2019-01-02 16:11 [PATCH v2 0/5] systemd patches Jonas Bonn
@ 2019-01-02 16:11 ` Jonas Bonn
  2019-01-02 16:11 ` [PATCH v2 2/5] systemd-conf: simplify creation of machine-specific configuration Jonas Bonn
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Jonas Bonn @ 2019-01-02 16:11 UTC (permalink / raw)
  To: openembedded-core

There is no reason to have an emtpy machine-id as part of the systemd
package.  Either:

i)  the filesystem is writable and the file will be created
automatically; or
ii) the filesystem is read-only, in which case the empty machine-id file
should be created as part of the read-only-rootfs tweaks.

Signed-off-by: Jonas Bonn <jonas@norrbonn.se>
---
 meta/classes/rootfs-postcommands.bbclass  | 6 ++++++
 meta/recipes-core/systemd/systemd-conf.bb | 9 ++-------
 meta/recipes-core/systemd/systemd_239.bb  | 1 -
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/meta/classes/rootfs-postcommands.bbclass b/meta/classes/rootfs-postcommands.bbclass
index bde58ad6cd..89f8efd323 100644
--- a/meta/classes/rootfs-postcommands.bbclass
+++ b/meta/classes/rootfs-postcommands.bbclass
@@ -126,6 +126,12 @@ read_only_rootfs_hook () {
 			${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
 		fi
 	fi
+
+	if ${@bb.utils.contains("DISTRO_FEATURES", "systemd", "true", "false", d)}; then
+	# Create machine-id
+	# 20:12 < mezcalero> koen: you have three options: a) run systemd-machine-id-setup at install time, b) have / read-only and an empty file there (for stateless) and c) boot with / writable
+		touch ${IMAGE_ROOTFS}${sysconfdir}/machine-id
+	fi
 }
 
 #
diff --git a/meta/recipes-core/systemd/systemd-conf.bb b/meta/recipes-core/systemd/systemd-conf.bb
index 9bb27fd96d..7fe2e1105b 100644
--- a/meta/recipes-core/systemd/systemd-conf.bb
+++ b/meta/recipes-core/systemd/systemd-conf.bb
@@ -7,14 +7,13 @@ DefaultTimeoutStartSec setting."
 
 PACKAGE_ARCH = "${MACHINE_ARCH}"
 
-CONFFILES_${PN} = "${sysconfdir}/machine-id \
-${sysconfdir}/systemd/coredump.conf \
+CONFFILES_${PN} = "${sysconfdir}/systemd/coredump.conf \
 ${sysconfdir}/systemd/journald.conf \
 ${sysconfdir}/systemd/logind.conf \
 ${sysconfdir}/systemd/system.conf \
 ${sysconfdir}/systemd/user.conf"
 
-FILES_${PN} = "${sysconfdir}/machine-id ${sysconfdir}/systemd"
+FILES_${PN} = "${sysconfdir}/systemd"
 
 do_configure[noexec] = '1'
 do_compile[noexec] = '1'
@@ -23,10 +22,6 @@ do_install() {
 	rm -rf ${D}/${sysconfdir}/systemd
 	install -d ${D}/${sysconfdir}/systemd
 
-	# Create machine-id
-	# 20:12 < mezcalero> koen: you have three options: a) run systemd-machine-id-setup at install time, b) have / read-only and an empty file there (for stateless) and c) boot with / writable
-	touch ${D}${sysconfdir}/machine-id
-
 	install -m 0644 ${S}/src/coredump/coredump.conf ${D}${sysconfdir}/systemd/coredump.conf
 
 	install -m 0644 ${S}/src/journal/journald.conf ${D}${sysconfdir}/systemd/journald.conf
diff --git a/meta/recipes-core/systemd/systemd_239.bb b/meta/recipes-core/systemd/systemd_239.bb
index 03acce25b7..0bb3276bf1 100644
--- a/meta/recipes-core/systemd/systemd_239.bb
+++ b/meta/recipes-core/systemd/systemd_239.bb
@@ -286,7 +286,6 @@ do_install() {
 	fi
 
 	# conf files are handled by systemd-conf
-	rm -f ${D}${sysconfdir}/machine-id
 	rm -f ${D}${sysconfdir}/systemd/coredump.conf
 	rm -f ${D}${sysconfdir}/systemd/journald.conf
 	rm -f ${D}${sysconfdir}/systemd/logind.conf
-- 
2.19.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/5] systemd-conf: simplify creation of machine-specific configuration
  2019-01-02 16:11 [PATCH v2 0/5] systemd patches Jonas Bonn
  2019-01-02 16:11 ` [PATCH v2 1/5] systemd: do not create machine-id Jonas Bonn
@ 2019-01-02 16:11 ` Jonas Bonn
  2019-01-02 16:11 ` [PATCH v2 3/5] systemd: create preset files instead of installing in image Jonas Bonn
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Jonas Bonn @ 2019-01-02 16:11 UTC (permalink / raw)
  To: openembedded-core

The configuration files that systemd installs are just skeletons
detailing the available options and their default values.  The
recommended means of changing the configuration is to provide snippets
in configuration directories.  For example, journald.conf settings are
best set in /usr/lib/journald.conf.d/ and can be overridden by the user
by providing overriding snippets in /etc/systemd/journald.conf.d/.

The systemd-conf package is just providing machine-specific overrides
for some systemd defaults.

This patch restores the installation of config files by systemd and
reduces systemd-conf to just providing the config snippets in
/usr/lib/*.conf.d.  This simplfies the systemd-conf recipe considerably
since it now just sets up a couple of text files and doesn't even need
access to the systemd source anymore.

Given, however, that the base configuration files in /etc/systemd have
the lowest priority, they will always be overridden by any snippets.  As
it may confuse a user who is used to modifying these base files
directly, this patch puts symlinks in the overriding
/etc/systemd/*.conf.d/ directories back to the top-level files, thereby
restoring them to their top-level glory.  The default config files
installed by systemd are just lists of (commented out) defaults so this
should be safe.  The symlinks also provide an indication to the user
that there is more to systemd configuration than just the top-level file
and that checking the man page may be in order...

With this patch, systemd gets the right configuration irregardless of
whether /etc is populated at boot or not (i.e. in a "stateless"
system).

License-Update: configuration snippets licensing is independent of
systemd licensing

Signed-off-by: Jonas Bonn <jonas@norrbonn.se>
---
 meta/recipes-core/systemd/systemd-conf.bb | 48 +++++++++++------------
 meta/recipes-core/systemd/systemd_239.bb  | 16 ++++----
 2 files changed, 31 insertions(+), 33 deletions(-)

diff --git a/meta/recipes-core/systemd/systemd-conf.bb b/meta/recipes-core/systemd/systemd-conf.bb
index 7fe2e1105b..8a9f01c48a 100644
--- a/meta/recipes-core/systemd/systemd-conf.bb
+++ b/meta/recipes-core/systemd/systemd-conf.bb
@@ -1,48 +1,44 @@
-require systemd.inc
-
 SUMMARY = "Systemd system configuration"
 DESCRIPTION = "Systemd may require slightly different configuration for \
 different machines.  For example, qemu machines require a longer \
 DefaultTimeoutStartSec setting."
+LICENSE = "MIT"
 
 PACKAGE_ARCH = "${MACHINE_ARCH}"
 
-CONFFILES_${PN} = "${sysconfdir}/systemd/coredump.conf \
-${sysconfdir}/systemd/journald.conf \
-${sysconfdir}/systemd/logind.conf \
-${sysconfdir}/systemd/system.conf \
-${sysconfdir}/systemd/user.conf"
-
-FILES_${PN} = "${sysconfdir}/systemd"
-
-do_configure[noexec] = '1'
-do_compile[noexec] = '1'
+FILES_${PN} = "/usr/lib/journald.conf.d/* \
+	/usr/lib/logind.conf.d/* \
+	/usr/lib/system.conf.d/* \
+	/etc/systemd/* \
+"
 
 do_install() {
-	rm -rf ${D}/${sysconfdir}/systemd
-	install -d ${D}/${sysconfdir}/systemd
-
-	install -m 0644 ${S}/src/coredump/coredump.conf ${D}${sysconfdir}/systemd/coredump.conf
-
-	install -m 0644 ${S}/src/journal/journald.conf ${D}${sysconfdir}/systemd/journald.conf
+	install -d ${D}/usr/lib/journald.conf.d
 	# Enable journal to forward message to syslog daemon
-	sed -i -e 's/.*ForwardToSyslog.*/ForwardToSyslog=yes/' ${D}${sysconfdir}/systemd/journald.conf
+	echo "ForwardToSyslog=yes" >> ${D}/usr/lib/journald.conf.d/00-${PN}.conf
 	# Set the maximium size of runtime journal to 64M as default
-	sed -i -e 's/.*RuntimeMaxUse.*/RuntimeMaxUse=64M/' ${D}${sysconfdir}/systemd/journald.conf
+	echo "RuntimeMaxUse=64M" >> ${D}/usr/lib/journald.conf.d/00-${PN}.conf
+
+	install -d ${D}${sysconfdir}/systemd/journald.conf.d
+	ln -s ../journald.conf ${D}${sysconfdir}/systemd/journald.conf.d/00-${PN}.conf
 
-	install -m 0644 ${S}/src/login/logind.conf.in ${D}${sysconfdir}/systemd/logind.conf
+	install -d ${D}/usr/lib/logind.conf.d
 	# Set KILL_USER_PROCESSES to yes
-	sed -i -e 's/@KILL_USER_PROCESSES@/yes/' ${D}${sysconfdir}/systemd/logind.conf
+	echo "KillUserProcesses=yes" >> ${D}/usr/lib/logind.conf.d/00-${PN}.conf
+
+	install -d ${D}${sysconfdir}/systemd/logind.conf.d
+	ln -s ../logind.conf ${D}${sysconfdir}/systemd/logind.conf.d/00-${PN}.conf
 
-	install -m 0644 ${S}/src/core/system.conf.in ${D}${sysconfdir}/systemd/system.conf
+	install -d ${D}/usr/lib/system.conf.d
 	# Set MEMORY_ACCOUNTING_DEFAULT to yes
-	sed -i -e 's/@MEMORY_ACCOUNTING_DEFAULT@/yes/' ${D}${sysconfdir}/systemd/system.conf
+	echo "DefaultMemoryAccounting=yes" >> ${D}/usr/lib/system.conf.d/00-${PN}.conf
 
-	install -m 0644 ${S}/src/core/user.conf ${D}${sysconfdir}/systemd/user.conf
+	install -d ${D}${sysconfdir}/systemd/system.conf.d
+	ln -s ../system.conf ${D}${sysconfdir}/systemd/system.conf.d/00-${PN}.conf
 }
 
 # Based on change from YP bug 8141, OE commit 5196d7bacaef1076c361adaa2867be31759c1b52
 do_install_append_qemuall() {
 	# Change DefaultTimeoutStartSec from 90s to 240s
-	echo "DefaultTimeoutStartSec = 240s" >> ${D}${sysconfdir}/systemd/system.conf
+	echo "DefaultTimeoutStartSec = 240s" >> ${D}/usr/lib/system.conf.d/00-${PN}.conf
 }
diff --git a/meta/recipes-core/systemd/systemd_239.bb b/meta/recipes-core/systemd/systemd_239.bb
index 0bb3276bf1..6800ff1f30 100644
--- a/meta/recipes-core/systemd/systemd_239.bb
+++ b/meta/recipes-core/systemd/systemd_239.bb
@@ -285,13 +285,6 @@ do_install() {
 		fi
 	fi
 
-	# conf files are handled by systemd-conf
-	rm -f ${D}${sysconfdir}/systemd/coredump.conf
-	rm -f ${D}${sysconfdir}/systemd/journald.conf
-	rm -f ${D}${sysconfdir}/systemd/logind.conf
-	rm -f ${D}${sysconfdir}/systemd/system.conf
-	rm -f ${D}${sysconfdir}/systemd/user.conf
-
 	# duplicate udevadm for postinst script
 	install -d ${D}${libexecdir}
 	ln ${D}${base_bindir}/udevadm ${D}${libexecdir}/${MLPREFIX}udevadm
@@ -486,6 +479,15 @@ FILES_${PN}-extra-utils = "\
                         ${rootlibexecdir}/systemd/systemd-cgroups-agent \
 "
 
+CONFFILES_${PN} = "${sysconfdir}/systemd/coredump.conf \
+	${sysconfdir}/systemd/journald.conf \
+	${sysconfdir}/systemd/logind.conf \
+	${sysconfdir}/systemd/system.conf \
+	${sysconfdir}/systemd/user.conf \
+	${sysconfdir}/systemd/resolved.conf \
+	${sysconfdir}/systemd/timesyncd.conf \
+"
+
 FILES_${PN} = " ${base_bindir}/* \
                 ${base_sbindir}/shutdown \
                 ${base_sbindir}/halt \
-- 
2.19.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/5] systemd: create preset files instead of installing in image
  2019-01-02 16:11 [PATCH v2 0/5] systemd patches Jonas Bonn
  2019-01-02 16:11 ` [PATCH v2 1/5] systemd: do not create machine-id Jonas Bonn
  2019-01-02 16:11 ` [PATCH v2 2/5] systemd-conf: simplify creation of machine-specific configuration Jonas Bonn
@ 2019-01-02 16:11 ` Jonas Bonn
  2019-01-07 16:43   ` Peter Kjellerstedt
  2019-01-02 16:11 ` [PATCH v2 4/5] systemd-systemctl-native: simplify and support preset-all Jonas Bonn
  2019-01-02 16:11 ` [PATCH v2 5/5] rootfs-postcommands: call preset-all for read-only-rootfs Jonas Bonn
  4 siblings, 1 reply; 8+ messages in thread
From: Jonas Bonn @ 2019-01-02 16:11 UTC (permalink / raw)
  To: openembedded-core

At first boot, systemd will create the /etc/systemd/system directory
from service preset files.  As such, for a normal, writable /etc
(writable rootfs), there is no need to set up this directory at image
creation time.

This patch changes the systemd machinery to create preset files and to
rely on systemd to do the service enablement.

This breaks the read-only-rootfs case; there's a fix for this in a
follow-up patch.

Signed-off-by: Jonas Bonn <jonas@norrbonn.se>
---
 meta/classes/systemd.bbclass | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/meta/classes/systemd.bbclass b/meta/classes/systemd.bbclass
index c7b784dea8..cf3b5de4a1 100644
--- a/meta/classes/systemd.bbclass
+++ b/meta/classes/systemd.bbclass
@@ -16,43 +16,32 @@ python __anonymous() {
     # from doing any work so that pure-systemd images don't have redundant init
     # files.
     if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d):
-        d.appendVar("DEPENDS", " systemd-systemctl-native")
-        d.appendVar("PACKAGE_WRITE_DEPS", " systemd-systemctl-native")
         if not bb.utils.contains('DISTRO_FEATURES', 'sysvinit', True, False, d):
             d.setVar("INHIBIT_UPDATERCD_BBCLASS", "1")
 }
 
 systemd_postinst() {
-OPTS=""
-
 if [ -n "$D" ]; then
-    OPTS="--root=$D"
+	exit 0
 fi
 
 if type systemctl >/dev/null 2>/dev/null; then
-	if [ -z "$D" ]; then
-		systemctl daemon-reload
-	fi
-
-	systemctl $OPTS ${SYSTEMD_AUTO_ENABLE} ${SYSTEMD_SERVICE_ESCAPED}
+	systemctl daemon-reload
+	systemctl preset ${SYSTEMD_SERVICE_ESCAPED}
 
-	if [ -z "$D" -a "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
+	if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
 		systemctl --no-block restart ${SYSTEMD_SERVICE_ESCAPED}
 	fi
 fi
 }
 
 systemd_prerm() {
-OPTS=""
-
 if [ -n "$D" ]; then
-    OPTS="--root=$D"
+	exit 0
 fi
 
 if type systemctl >/dev/null 2>/dev/null; then
-	if [ -z "$D" ]; then
-		systemctl stop ${SYSTEMD_SERVICE_ESCAPED}
-	fi
+	systemctl stop ${SYSTEMD_SERVICE_ESCAPED}
 
 	systemctl $OPTS disable ${SYSTEMD_SERVICE_ESCAPED}
 fi
@@ -177,12 +166,22 @@ python systemd_populate_packages() {
                 else:
                     bb.fatal("SYSTEMD_SERVICE_%s value %s does not exist" % (pkg_systemd, service))
 
+    def systemd_create_presets(pkg):
+        action = get_package_var(d, 'SYSTEMD_AUTO_ENABLE', pkg)
+        presetf = oe.path.join(d.getVar("PKGD"), "/lib/systemd/system-preset/98-%s.preset" % pkg)
+        bb.utils.mkdirhier(os.path.dirname(presetf))
+        with open(presetf, 'a') as fd:
+            for service in d.getVar('SYSTEMD_SERVICE_%s' % pkg).split():
+                fd.write("%s %s\n" % (action,service))
+        d.appendVar("FILES_%s" % pkg, " /lib/systemd/system-preset/98-%s.preset" % pkg)
+
     # Run all modifications once when creating package
     if os.path.exists(d.getVar("D")):
         for pkg in d.getVar('SYSTEMD_PACKAGES').split():
             systemd_check_package(pkg)
             if d.getVar('SYSTEMD_SERVICE_' + pkg):
                 systemd_generate_package_scripts(pkg)
+                systemd_create_presets(pkg)
         systemd_check_services()
 }
 
-- 
2.19.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 4/5] systemd-systemctl-native: simplify and support preset-all
  2019-01-02 16:11 [PATCH v2 0/5] systemd patches Jonas Bonn
                   ` (2 preceding siblings ...)
  2019-01-02 16:11 ` [PATCH v2 3/5] systemd: create preset files instead of installing in image Jonas Bonn
@ 2019-01-02 16:11 ` Jonas Bonn
  2019-01-02 16:11 ` [PATCH v2 5/5] rootfs-postcommands: call preset-all for read-only-rootfs Jonas Bonn
  4 siblings, 0 replies; 8+ messages in thread
From: Jonas Bonn @ 2019-01-02 16:11 UTC (permalink / raw)
  To: openembedded-core

Now that the systemd class sets up service presets instead of actively
enabling services, the 'enable' and 'disable' subcommands for systemctl
are not actually used anywhere.  As such, we can remove these to make
sure that nobody inadvertently introduces new uses of them.

We do, however, one case where the enable/disable machinery is still
required; that is for the read-only-rootfs case where the 'preset-all'
command can not be called at runtime but needs to be called when creatng
the image.  For this case, we implement 'preset-all' here.

There was also a previous implement of 'preset'... not sure that this
ever worked as the implementation looks bogus and there aren't any users
anyway.  This patch removes the 'preset' subcommand, as well.

Signed-off-by: Jonas Bonn <jonas@norrbonn.se>
---
 .../systemd/systemd-systemctl/systemctl       | 36 ++++---------------
 1 file changed, 7 insertions(+), 29 deletions(-)

diff --git a/meta/recipes-core/systemd/systemd-systemctl/systemctl b/meta/recipes-core/systemd/systemd-systemctl/systemctl
index 2bc6489617..ce50352018 100755
--- a/meta/recipes-core/systemd/systemd-systemctl/systemctl
+++ b/meta/recipes-core/systemd/systemd-systemctl/systemctl
@@ -9,22 +9,6 @@ while [ $# != 0 ]; do
 	opt="$1"
 
 	case "$opt" in
-		enable)
-			shift
-
-			action="$opt"
-			services="$1"
-			cmd_args="1"
-			shift
-			;;
-		disable)
-			shift
-
-			action="$opt"
-			services="$1"
-			cmd_args="1"
-			shift
-			;;
 		mask)
 			shift
 
@@ -33,13 +17,11 @@ while [ $# != 0 ]; do
 			cmd_args="1"
 			shift
 			;;
-		preset)
+		preset-all)
 			shift
 
 			action="$opt"
-			services="$1"
-			cmd_args="1"
-			shift
+			cmd_args="0"
 			;;
 		--root=*)
 			ROOT=${opt##--root=}
@@ -57,16 +39,12 @@ while [ $# != 0 ]; do
 			;;
 	esac
 done
-if [ "$action" = "preset" -a "$service_file" = "" ]; then
+
+if [ "$action" = "preset-all" ]; then
 	services=$(for f in `find $ROOT/etc/systemd/system $ROOT/lib/systemd/system $ROOT/usr/lib/systemd/system -type f 2>1`; do basename $f; done)
-	services="$services $opt"
-	presetall=1
 fi
 
 for service in $services; do
-	if [ "$presetall" = "1" ]; then
-		action="preset"
-	fi
 	if [ "$action" = "mask" ]; then
 		if [ ! -d $ROOT/etc/systemd/system/ ]; then
 			mkdir -p $ROOT/etc/systemd/system/
@@ -105,10 +83,10 @@ for service in $services; do
 	# If any new unit types are added to systemd they should be added
 	# to this regular expression.
 	unit_types_re='\.\(service\|socket\|device\|mount\|automount\|swap\|target\|target\.wants\|path\|timer\|snapshot\)\s*$'
-	if [ "$action" = "preset" ]; then
-		action=`egrep -sh  $service $ROOT/etc/systemd/user-preset/*.preset | cut -f1 -d' '`
+	if [ "$action" = "preset-all" ]; then
+		action=`egrep -sh  $service $ROOT/usr/lib/systemd/system-preset/*.preset | cut -f1 -d' '`
 		if [ -z "$action" ]; then
-			globalpreset=`egrep -sh  '\*'  $ROOT/etc/systemd/user-preset/*.preset | cut -f1 -d' '`
+			globalpreset=`egrep -sh  '\*'  $ROOT/usr/lib/systemd/system-preset/*.preset | cut -f1 -d' '`
 			if [ -n "$globalpreset" ]; then
 				action="$globalpreset"
 			else
-- 
2.19.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 5/5] rootfs-postcommands: call preset-all for read-only-rootfs
  2019-01-02 16:11 [PATCH v2 0/5] systemd patches Jonas Bonn
                   ` (3 preceding siblings ...)
  2019-01-02 16:11 ` [PATCH v2 4/5] systemd-systemctl-native: simplify and support preset-all Jonas Bonn
@ 2019-01-02 16:11 ` Jonas Bonn
  4 siblings, 0 replies; 8+ messages in thread
From: Jonas Bonn @ 2019-01-02 16:11 UTC (permalink / raw)
  To: openembedded-core

When the rootfs is read-only, we cannot rely on systemd's default
invocation of preset-all at runtime in order to enable services.  As
such, we need to do it at image creation time.

Signed-off-by: Jonas Bonn <jonas@norrbonn.se>
---
 meta/classes/rootfs-postcommands.bbclass | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/meta/classes/rootfs-postcommands.bbclass b/meta/classes/rootfs-postcommands.bbclass
index 89f8efd323..5fcd53c4ca 100644
--- a/meta/classes/rootfs-postcommands.bbclass
+++ b/meta/classes/rootfs-postcommands.bbclass
@@ -16,6 +16,7 @@ ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp ; "
 
 # Tweak the mount options for rootfs in /etc/fstab if read-only-rootfs is enabled
 ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}'
+IMAGE_EXTRADEPENDS += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "systemd-systemctl-native", "", d)}'
 
 # We also need to do the same for the kernel boot parameters,
 # otherwise kernel or initramfs end up mounting the rootfs read/write
@@ -131,6 +132,7 @@ read_only_rootfs_hook () {
 	# Create machine-id
 	# 20:12 < mezcalero> koen: you have three options: a) run systemd-machine-id-setup at install time, b) have / read-only and an empty file there (for stateless) and c) boot with / writable
 		touch ${IMAGE_ROOTFS}${sysconfdir}/machine-id
+		systemctl --root=${IMAGE_ROOTFS} preset-all
 	fi
 }
 
-- 
2.19.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 3/5] systemd: create preset files instead of installing in image
  2019-01-02 16:11 ` [PATCH v2 3/5] systemd: create preset files instead of installing in image Jonas Bonn
@ 2019-01-07 16:43   ` Peter Kjellerstedt
  2019-01-08 14:58     ` Jonas Bonn
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Kjellerstedt @ 2019-01-07 16:43 UTC (permalink / raw)
  To: Jonas Bonn; +Cc: openembedded-core

> -----Original Message-----
> From: openembedded-core-bounces@lists.openembedded.org <openembedded-
> core-bounces@lists.openembedded.org> On Behalf Of Jonas Bonn
> Sent: den 2 januari 2019 17:12
> To: openembedded-core@lists.openembedded.org
> Subject: [OE-core] [PATCH v2 3/5] systemd: create preset files instead
> of installing in image
> 
> At first boot, systemd will create the /etc/systemd/system directory
> from service preset files.  As such, for a normal, writable /etc
> (writable rootfs), there is no need to set up this directory at image
> creation time.
> 
> This patch changes the systemd machinery to create preset files and to
> rely on systemd to do the service enablement.
> 
> This breaks the read-only-rootfs case; there's a fix for this in a
> follow-up patch.
> 
> Signed-off-by: Jonas Bonn <jonas@norrbonn.se>
> ---
>  meta/classes/systemd.bbclass | 33 ++++++++++++++++-----------------
>  1 file changed, 16 insertions(+), 17 deletions(-)
> 
> diff --git a/meta/classes/systemd.bbclass
> b/meta/classes/systemd.bbclass
> index c7b784dea8..cf3b5de4a1 100644
> --- a/meta/classes/systemd.bbclass
> +++ b/meta/classes/systemd.bbclass
> @@ -16,43 +16,32 @@ python __anonymous() {
>      # from doing any work so that pure-systemd images don't have redundant init
>      # files.
>      if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d):
> -        d.appendVar("DEPENDS", " systemd-systemctl-native")
> -        d.appendVar("PACKAGE_WRITE_DEPS", " systemd-systemctl-native")
>          if not bb.utils.contains('DISTRO_FEATURES', 'sysvinit', True, False, d):
>              d.setVar("INHIBIT_UPDATERCD_BBCLASS", "1")
>  }
> 
>  systemd_postinst() {
> -OPTS=""
> -
>  if [ -n "$D" ]; then
> -    OPTS="--root=$D"
> +	exit 0
>  fi
> 
>  if type systemctl >/dev/null 2>/dev/null; then
> -	if [ -z "$D" ]; then
> -		systemctl daemon-reload
> -	fi
> -
> -	systemctl $OPTS ${SYSTEMD_AUTO_ENABLE} ${SYSTEMD_SERVICE_ESCAPED}
> +	systemctl daemon-reload
> +	systemctl preset ${SYSTEMD_SERVICE_ESCAPED}
> 
> -	if [ -z "$D" -a "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
> +	if [ "${SYSTEMD_AUTO_ENABLE}" = "enable" ]; then
>  		systemctl --no-block restart ${SYSTEMD_SERVICE_ESCAPED}
>  	fi
>  fi
>  }
> 
>  systemd_prerm() {
> -OPTS=""
> -
>  if [ -n "$D" ]; then
> -    OPTS="--root=$D"
> +	exit 0
>  fi
> 
>  if type systemctl >/dev/null 2>/dev/null; then
> -	if [ -z "$D" ]; then
> -		systemctl stop ${SYSTEMD_SERVICE_ESCAPED}
> -	fi
> +	systemctl stop ${SYSTEMD_SERVICE_ESCAPED}
> 
>  	systemctl $OPTS disable ${SYSTEMD_SERVICE_ESCAPED}
>  fi
> @@ -177,12 +166,22 @@ python systemd_populate_packages() {
>                  else:
>                      bb.fatal("SYSTEMD_SERVICE_%s value %s does not exist" % (pkg_systemd, service))
> 
> +    def systemd_create_presets(pkg):
> +        action = get_package_var(d, 'SYSTEMD_AUTO_ENABLE', pkg)
> +        presetf = oe.path.join(d.getVar("PKGD"), "/lib/systemd/system-preset/98-%s.preset" % pkg)

Using "/lib" above does not take into account the usrmerge distro 
feature. My suggestion is to use ${nonarch_base_libdir} instead of 
/lib, or maybe even better is to use ${systemd_unitdir} instead of 
/lib/systemd, i.e.:

        presetf = oe.path.join(d.getVar("PKGD"), d.getVar("systemd_unitdir "), "/system-preset/98-%s.preset" % pkg)

> +        bb.utils.mkdirhier(os.path.dirname(presetf))
> +        with open(presetf, 'a') as fd:
> +            for service in d.getVar('SYSTEMD_SERVICE_%s' % pkg).split():
> +                fd.write("%s %s\n" % (action,service))
> +        d.appendVar("FILES_%s" % pkg, " /lib/systemd/system-preset/98-%s.preset" % pkg)

Same here. Use "${systemd_unitdir}" instead of "/lib/systemd".

> +
>      # Run all modifications once when creating package
>      if os.path.exists(d.getVar("D")):
>          for pkg in d.getVar('SYSTEMD_PACKAGES').split():
>              systemd_check_package(pkg)
>              if d.getVar('SYSTEMD_SERVICE_' + pkg):
>                  systemd_generate_package_scripts(pkg)
> +                systemd_create_presets(pkg)
>          systemd_check_services()
>  }
> 
> --
> 2.19.1

//Peter



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 3/5] systemd: create preset files instead of installing in image
  2019-01-07 16:43   ` Peter Kjellerstedt
@ 2019-01-08 14:58     ` Jonas Bonn
  0 siblings, 0 replies; 8+ messages in thread
From: Jonas Bonn @ 2019-01-08 14:58 UTC (permalink / raw)
  To: Peter Kjellerstedt; +Cc: openembedded-core

Hi Peter,


On 07/01/2019 17:43, Peter Kjellerstedt wrote:
>> -----Original Message-----
>> From: openembedded-core-bounces@lists.openembedded.org <openembedded-
>> core-bounces@lists.openembedded.org> On Behalf Of Jonas Bonn
>>
>> +    def systemd_create_presets(pkg):
>> +        action = get_package_var(d, 'SYSTEMD_AUTO_ENABLE', pkg)
>> +        presetf = oe.path.join(d.getVar("PKGD"), "/lib/systemd/system-preset/98-%s.preset" % pkg)
> 
> Using "/lib" above does not take into account the usrmerge distro
> feature. My suggestion is to use ${nonarch_base_libdir} instead of
> /lib, or maybe even better is to use ${systemd_unitdir} instead of
> /lib/systemd, i.e.:

Yes.  I already had this fixed up locally but using ${systemd_unitdir} 
is smarter than what I've got so I'll do it that way before resubmitting.

Thanks for the review!
/Jonas


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-01-08 14:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-02 16:11 [PATCH v2 0/5] systemd patches Jonas Bonn
2019-01-02 16:11 ` [PATCH v2 1/5] systemd: do not create machine-id Jonas Bonn
2019-01-02 16:11 ` [PATCH v2 2/5] systemd-conf: simplify creation of machine-specific configuration Jonas Bonn
2019-01-02 16:11 ` [PATCH v2 3/5] systemd: create preset files instead of installing in image Jonas Bonn
2019-01-07 16:43   ` Peter Kjellerstedt
2019-01-08 14:58     ` Jonas Bonn
2019-01-02 16:11 ` [PATCH v2 4/5] systemd-systemctl-native: simplify and support preset-all Jonas Bonn
2019-01-02 16:11 ` [PATCH v2 5/5] rootfs-postcommands: call preset-all for read-only-rootfs Jonas Bonn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.