[RFC PATCH 0/2] debianize: Use dh_installsystemd

2 views
Skip to first unread message

Quirin Gylstorff

unread,
Feb 1, 2024, 8:07:57 AM2/1/24
to isar-...@googlegroups.com
From: Quirin Gylstorff <quirin.g...@siemens.com>

This series adds the variable DEBIAN_SYSTEMD_SERVICE which defines
a systemd file to automatically be added to the debian folder and
automatically installed by using `dh_installsystemd`.

Quirin Gylstorff (2):
debianize: use dh_installsystemd to automatically add systemd service
meta/recipe-support: Use DEBIAN_SYSTEMD_SERVICE variable

meta/classes/debianize.bbclass | 15 +++++++++++++++
meta/recipes-support/enable-fsck/enable-fsck.bb | 6 ++----
meta/recipes-support/enable-fsck/files/postinst | 3 ---
.../expand-on-first-boot_1.4.bb | 7 ++-----
.../expand-on-first-boot/files/postinst | 3 ---
.../sshd-regen-keys/sshd-regen-keys_0.4.bb | 1 +
6 files changed, 20 insertions(+), 15 deletions(-)
delete mode 100644 meta/recipes-support/enable-fsck/files/postinst
delete mode 100644 meta/recipes-support/expand-on-first-boot/files/postinst

--
2.43.0

Quirin Gylstorff

unread,
Feb 1, 2024, 8:07:58 AM2/1/24
to isar-...@googlegroups.com
From: Quirin Gylstorff <quirin.g...@siemens.com>

Copy the file in `DEBIAN_SYSTEMD_SERVICE` to the folder if it has the
same name as the debian package. This will use dh_installsystemd.

Debian detects any of the following files in the debian folder
they are installed into usr/lib/systemd/system/ in the package build directory:
- package.mount
- package.path
- package@.path
- package.service
- package@.service
- package.socket
- package@.socket
- package.target
- package@.target
- package.timer
- package@.timer

Signed-off-by: Quirin Gylstorff <quirin.g...@siemens.com>
---
meta/classes/debianize.bbclass | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/meta/classes/debianize.bbclass b/meta/classes/debianize.bbclass
index 7de98673..5015d52c 100644
--- a/meta/classes/debianize.bbclass
+++ b/meta/classes/debianize.bbclass
@@ -11,6 +11,7 @@ DEBIAN_DEPENDS ??= ""
DEBIAN_CONFLICTS ??= ""
DEBIAN_MULTI_ARCH ??= "no"
DEBIAN_COMPAT ??= "10"
+DEBIAN_SYSTEMD_SERVICE ??= ""
DESCRIPTION ??= "must not be empty"
MAINTAINER ??= "Unknown maintainer <unk...@example.com>"

@@ -116,12 +117,26 @@ deb_debianize() {
# contains an entry with CHANGELOG_V
deb_add_changelog

+ # copy service files to debian folder
+ # this will automatically enable the service
+ service_installed=""
+ if [ -n "${DEBIAN_SYSTEMD_SERVICE}" ]; then
+ service_name=$(echo ${DEBIAN_SYSTEMD_SERVICE} | awk -F. '{print $1}')
+ if [ "$service_name" = "${BPN}" ] && [ -f ${WORKDIR}/${DEBIAN_SYSTEMD_SERVICE} ]; then
+ install -v -m 644 ${WORKDIR}/${DEBIAN_SYSTEMD_SERVICE} ${S}/debian/
+ fi
+ service_installed="true"
+ fi
+
# copy all hooks from WORKDIR into debian/, hooks are not generated
for t in pre post
do
for a in inst rm
do
if [ -f ${WORKDIR}/${t}${a} ]; then
+ if [ "$service_installed" = "true" ]; then
+ bbwarn "systemd service '${BPN}.service' exists and is added automacially to the debian folder."
+ fi
install -v -m 755 ${WORKDIR}/${t}${a} \
${S}/debian/${t}${a}
fi
--
2.43.0

Quirin Gylstorff

unread,
Feb 1, 2024, 8:07:59 AM2/1/24
to isar-...@googlegroups.com
From: Quirin Gylstorff <quirin.g...@siemens.com>

Change recipes to use the new DEBIAN_SYSTEMD_SERVICE variable.

Also add comment to sshd-regen-keys to explain usage of the
old mechanism.

Signed-off-by: Quirin Gylstorff <quirin.g...@siemens.com>
---
meta/recipes-support/enable-fsck/enable-fsck.bb | 6 ++----
meta/recipes-support/enable-fsck/files/postinst | 3 ---
.../expand-on-first-boot/expand-on-first-boot_1.4.bb | 7 ++-----
meta/recipes-support/expand-on-first-boot/files/postinst | 3 ---
.../recipes-support/sshd-regen-keys/sshd-regen-keys_0.4.bb | 1 +
5 files changed, 5 insertions(+), 15 deletions(-)
delete mode 100644 meta/recipes-support/enable-fsck/files/postinst
delete mode 100644 meta/recipes-support/expand-on-first-boot/files/postinst

diff --git a/meta/recipes-support/enable-fsck/enable-fsck.bb b/meta/recipes-support/enable-fsck/enable-fsck.bb
index 0413f79d..b68d8f76 100644
--- a/meta/recipes-support/enable-fsck/enable-fsck.bb
+++ b/meta/recipes-support/enable-fsck/enable-fsck.bb
@@ -10,16 +10,14 @@ inherit dpkg-raw
DESCRIPTION = "This service enables fsck on first boot"

DEBIAN_DEPENDS = "systemd, sed, mount, initramfs-tools"
+DEBIAN_SYSTEMD_SERVICE = "enable-fsck.service"

SRC_URI = " \
file://enable-fsck.service \
file://enable-fsck.sh \
- file://postinst"
+ "

do_install() {
- install -d -m 755 ${D}/lib/systemd/system
- install -m 644 ${WORKDIR}/enable-fsck.service ${D}/lib/systemd/system/
-
install -d -m 755 ${D}/usr/share/enable-fsck
install -m 755 ${WORKDIR}/enable-fsck.sh ${D}/usr/share/enable-fsck/
}
diff --git a/meta/recipes-support/enable-fsck/files/postinst b/meta/recipes-support/enable-fsck/files/postinst
deleted file mode 100644
index 1c4c3bdb..00000000
--- a/meta/recipes-support/enable-fsck/files/postinst
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-systemctl enable enable-fsck.service
diff --git a/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.4.bb b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.4.bb
index 0996000c..a24d1e9c 100644
--- a/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.4.bb
+++ b/meta/recipes-support/expand-on-first-boot/expand-on-first-boot_1.4.bb
@@ -11,16 +11,13 @@ DESCRIPTION = "This service grows the last partition to the full medium during f
MAINTAINER = "isar-users <isar-...@googlegroups.com>"

DEBIAN_DEPENDS = "systemd, sed, grep, coreutils, mount, e2fsprogs, fdisk (>=2.29.2-3) | util-linux (<2.29.2-3), util-linux"
+DEBIAN_SYSTEMD_SERVICE = "expand-on-first-boot.service"

SRC_URI = " \
file://expand-on-first-boot.service \
file://expand-last-partition.sh \
- file://postinst"
-
+ "
do_install() {
- install -d -m 755 ${D}/lib/systemd/system
- install -m 644 ${WORKDIR}/expand-on-first-boot.service ${D}/lib/systemd/system/
-
install -d -m 755 ${D}/usr/share/expand-on-first-boot
install -m 755 ${WORKDIR}/expand-last-partition.sh ${D}/usr/share/expand-on-first-boot/
}
diff --git a/meta/recipes-support/expand-on-first-boot/files/postinst b/meta/recipes-support/expand-on-first-boot/files/postinst
deleted file mode 100644
index a190b01a..00000000
--- a/meta/recipes-support/expand-on-first-boot/files/postinst
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-systemctl enable expand-on-first-boot.service
diff --git a/meta/recipes-support/sshd-regen-keys/sshd-regen-keys_0.4.bb b/meta/recipes-support/sshd-regen-keys/sshd-regen-keys_0.4.bb
index 9ce1d8d8..b6d60814 100644
--- a/meta/recipes-support/sshd-regen-keys/sshd-regen-keys_0.4.bb
+++ b/meta/recipes-support/sshd-regen-keys/sshd-regen-keys_0.4.bb
@@ -5,6 +5,7 @@ DESCRIPTION = "Systemd service to regenerate sshd keys"
MAINTAINER = "isar-users <isar-...@googlegroups.com>"
DEBIAN_DEPENDS = "openssh-server, systemd"

+# postinst also removes exiting ssh keys
SRC_URI = "file://postinst \
file://sshd-regen-keys.service"

--
2.43.0

MOESSBAUER, Felix

unread,
Feb 1, 2024, 10:16:39 AM2/1/24
to quirin.g...@siemens.com, isar-...@googlegroups.com
On Thu, 2024-02-01 at 14:07 +0100, 'Quirin Gylstorff' via isar-users
wrote:
> From: Quirin Gylstorff <quirin.g...@siemens.com>
>
> This series adds the variable DEBIAN_SYSTEMD_SERVICE which defines
> a systemd file to automatically be added to the debian folder and
> automatically installed by using `dh_installsystemd`.

Hi, do we really need that interface?

Usually you just copy these files into the debian folder in
do_prepare_build. That's it.

There are also more files which get picked up by the debhelpers.

Best regards,
Felix

>
> Quirin Gylstorff (2):
>   debianize: use dh_installsystemd to automatically add systemd
> service
>   meta/recipe-support: Use DEBIAN_SYSTEMD_SERVICE variable
>
>  meta/classes/debianize.bbclass                    | 15
> +++++++++++++++
>  meta/recipes-support/enable-fsck/enable-fsck.bb   |  6 ++----
>  meta/recipes-support/enable-fsck/files/postinst   |  3 ---
>  .../expand-on-first-boot_1.4.bb                   |  7 ++-----
>  .../expand-on-first-boot/files/postinst           |  3 ---
>  .../sshd-regen-keys/sshd-regen-keys_0.4.bb        |  1 +
>  6 files changed, 20 insertions(+), 15 deletions(-)
>  delete mode 100644 meta/recipes-support/enable-fsck/files/postinst
>  delete mode 100644 meta/recipes-support/expand-on-first-
> boot/files/postinst
>
> --
> 2.43.0
>

--
Siemens AG, Technology
Linux Expert Center


Gylstorff Quirin

unread,
Feb 1, 2024, 10:48:55 AM2/1/24
to Moessbauer, Felix (T CED OES-DE), isar-...@googlegroups.com


On 2/1/24 16:16, Moessbauer, Felix (T CED OES-DE) wrote:
> On Thu, 2024-02-01 at 14:07 +0100, 'Quirin Gylstorff' via isar-users
> wrote:
>> From: Quirin Gylstorff <quirin.g...@siemens.com>
>>
>> This series adds the variable DEBIAN_SYSTEMD_SERVICE which defines
>> a systemd file to automatically be added to the debian folder and
>> automatically installed by using `dh_installsystemd`.
>
> Hi, do we really need that interface?
>
> Usually you just copy these files into the debian folder in
> do_prepare_build. That's it.
>
> There are also more files which get picked up by the debhelpers.

We have multiple location and files where the do_install pattern is
used:
```
file://postinst"
"

do_install() {
install -d -m 755 ${D}/lib/systemd/system
install -m 644 ${WORKDIR}/enable-fsck.service ${D}/lib/systemd/system/
```

If the the do_prepare_build pattern is sufficient we can also change all
service:

```
do_prepare_build:append() {
install -m 644 ${WORKDIR}/enable-fsck.service ${S}/debian

}
```

Quirin

Anton Mikanovich

unread,
Feb 1, 2024, 10:52:44 AM2/1/24
to Gylstorff Quirin, Moessbauer, Felix (T CED OES-DE), isar-...@googlegroups.com
01/02/2024 17:48, 'Gylstorff Quirin' via isar-users wrote:
>
> We have multiple location and files where the do_install pattern is
> used:
> ```
>     file://postinst"
>     "
>
>  do_install() {
>     install -d -m 755 ${D}/lib/systemd/system
>     install -m 644 ${WORKDIR}/enable-fsck.service
> ${D}/lib/systemd/system/
> ```
>
> If the the do_prepare_build pattern is sufficient we can also change
> all service:
>
> ```
> do_prepare_build:append() {
>     install -m 644 ${WORKDIR}/enable-fsck.service ${S}/debian
>
> }
> ```
>
> Quirin
>
I hope the same can be done by subdir=debian in SRC_URI, not sure about
dpkg-raw recipes.

MOESSBAUER, Felix

unread,
Feb 15, 2024, 3:43:03 AM2/15/24
to quirin.g...@siemens.com, isar-...@googlegroups.com
This in principle is a good pattern, but is prone to rebuild errors as
${S}/debian is not cleaned beforehand. Unfortunately we cannot always
add do_prepare_build[cleandirs] += "${S}/debian", as this runs after
the do_unpack which might already place files there.

Maybe just add this line to the respective recipes?

Felix

> ```
>
> Quirin
> >
> > Best regards,
> > Felix
> >
> > >
> > > Quirin Gylstorff (2):
> > >    debianize: use dh_installsystemd to automatically add systemd
> > > service
> > >    meta/recipe-support: Use DEBIAN_SYSTEMD_SERVICE variable
> > >
> > >   meta/classes/debianize.bbclass                    | 15
> > > +++++++++++++++
> > >   meta/recipes-support/enable-fsck/enable-fsck.bb   |  6 ++----
> > >   meta/recipes-support/enable-fsck/files/postinst   |  3 ---
> > >   .../expand-on-first-boot_1.4.bb                   |  7 ++-----
> > >   .../expand-on-first-boot/files/postinst           |  3 ---
> > >   .../sshd-regen-keys/sshd-regen-keys_0.4.bb        |  1 +
> > >   6 files changed, 20 insertions(+), 15 deletions(-)
> > >   delete mode 100644 meta/recipes-support/enable-
> > > fsck/files/postinst
> > >   delete mode 100644 meta/recipes-support/expand-on-first-
> > > boot/files/postinst
> > >
> > > --
> > > 2.43.0
> > >
> >

Reply all
Reply to author
Forward
0 new messages