diff mbox series

[meta-swupdate,v5,1/2] swupdate: improve systemd config

Message ID 20191104155425.28233-2-adrian.freihofer@siemens.com
State Accepted
Headers show
Series simplify swupdate config | expand

Commit Message

Freihofer, Adrian Nov. 4, 2019, 3:54 p.m. UTC
For most projects starting swupdate requires some logic implemented
in shell scripts. Therefore swupdate is now started by a shell script
if systemd is enabled in DISTRO_FEATURES.

The new swupdate startup script sources code snippets located in
/usr/lib/swupdate/conf.d and in /etc/swupdate/conf.d. The snippets are
executed in alphabetical order. The idea is that files in /usr are added
at build time and files in /etc might be added or modified at run-time.
If two scripts, one in /etc and one in /usr have the same file name, the
script in /usr gets skipped completely. This allows to disable code in
/usr, which is probably mounted ro, at runtime.

Code snippets are automatically generated at build-time, depending on
the configuration created by swupdate's menuconfig. But code snippets
may be created manually and added via bbappend to the
/usr/lib/swupdate/conf.d folder as well.

All modes (file, webserver, webclient) of swupdate are supported.
Different variables might be defined by the code snippets added to the
named folders:
- SWUPDATE_ARGS
- SWUPDATE_WEBSERVER_ARGS
- SWUPDATE_DOWNLOAD_ARGS

Finally swupdate gets started by a line similar to:

  exec /usr/bin/swupdate $SWUPDATE_ARGS \
                         -w "$SWUPDATE_WEBSERVER_ARGS" \
                         -u "$SWUPDATE_DOWNLOAD_ARGS"

The default set of configuraton and service files is now installed by
the "make install" target of the swupdate Makefile. The service files
which are not used for the latest git version of swupdate are moved
to swupdate-2019.04 folder.

Fixes in do_install
- This changes the filenames of the tools binaries for several reasons:
  - Binaries should not be named "client" or "progress"
    (also not accepted by Debian upstream)
  - Inconsistent with names referred in the service files
- The swupdate_tools.inc file gets merged into swupdate.inc file. By
  removing the tools file some bugs are fixed:
  - The tools binaries were installed twice.
  - do_compile from swupdate.inc was over written resulting in wired
    behavior
  - swupdate-progress.service file was part of swupdate package were
    the corresponding swupdate-progress binary was part of the tools
    package.

Improve package splitting
- New packages are: swupdate-client, swupdate-progress, swupdate-usb,
  swupdate-tools-hawkbit.
- Additionally swupdate-sd, swupdate-sv, swupdate-usb-sd and
  swupdate-progress-sd have been introduced. The purpose of the -sd
  and -sv packages is to provide the systemd service files or the
  sysv init scripts. Splitting the init scripts and service files is
  very atypical for Yocto, but it offers the flexibility to build a
  second minimal rescue image with sysv, just capable to run swupdate,
  out of the same DISTRO.
  By default (if not changed by a bbappend file) the rdepends are
  set e.g. from swupdate-usb to swupdate-sd, if systemd is enabled.
- The swupdate-tools package is an empty meta package now. It provides
  backward compatibility for setups installing swupdate-tools. It
  depends on swupdate-client, swupdate-progress, swupdate-usb,
  swupdate-tools-hawkbit packages.

Remove the INSANE_SKIP_${PN} = "ldflags". Seems obsolete.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 .../swupdate-progress.service                      |  0
 .../swupdate-usb.rules                             |  0
 .../swupdate-usb@.service                          |  0
 .../swupdate.service                               |  0
 .../systemd-tmpfiles-swupdate.conf                 |  0
 recipes-support/swupdate/swupdate.inc              | 98 +++++++++++++++-------
 recipes-support/swupdate/swupdate_2019.04.bb       | 28 ++++++-
 recipes-support/swupdate/swupdate_git.bb           |  5 +-
 recipes-support/swupdate/swupdate_tools.inc        | 24 ------
 9 files changed, 97 insertions(+), 58 deletions(-)
 rename recipes-support/swupdate/{swupdate => swupdate-2019.04}/swupdate-progress.service (100%)
 rename recipes-support/swupdate/{swupdate => swupdate-2019.04}/swupdate-usb.rules (100%)
 rename recipes-support/swupdate/{swupdate => swupdate-2019.04}/swupdate-usb@.service (100%)
 rename recipes-support/swupdate/{swupdate => swupdate-2019.04}/swupdate.service (100%)
 rename recipes-support/swupdate/{swupdate => swupdate-2019.04}/systemd-tmpfiles-swupdate.conf (100%)
 delete mode 100644 recipes-support/swupdate/swupdate_tools.inc

Comments

Stefano Babic Nov. 10, 2019, 12:43 p.m. UTC | #1
Hi Adrian,

after some tests on projects using SysVInit als init manager, I applied
your patches with a restriction:

On 04/11/19 16:54, Adrian Freihofer wrote:
> For most projects starting swupdate requires some logic implemented
> in shell scripts. Therefore swupdate is now started by a shell script
> if systemd is enabled in DISTRO_FEATURES.
> 
> The new swupdate startup script sources code snippets located in
> /usr/lib/swupdate/conf.d and in /etc/swupdate/conf.d. The snippets are
> executed in alphabetical order. The idea is that files in /usr are added
> at build time and files in /etc might be added or modified at run-time.
> If two scripts, one in /etc and one in /usr have the same file name, the
> script in /usr gets skipped completely. This allows to disable code in
> /usr, which is probably mounted ro, at runtime.
> 
> Code snippets are automatically generated at build-time, depending on
> the configuration created by swupdate's menuconfig. But code snippets
> may be created manually and added via bbappend to the
> /usr/lib/swupdate/conf.d folder as well.
> 
> All modes (file, webserver, webclient) of swupdate are supported.
> Different variables might be defined by the code snippets added to the
> named folders:
> - SWUPDATE_ARGS
> - SWUPDATE_WEBSERVER_ARGS
> - SWUPDATE_DOWNLOAD_ARGS
> 
> Finally swupdate gets started by a line similar to:
> 
>   exec /usr/bin/swupdate $SWUPDATE_ARGS \
>                          -w "$SWUPDATE_WEBSERVER_ARGS" \
>                          -u "$SWUPDATE_DOWNLOAD_ARGS"
> 
> The default set of configuraton and service files is now installed by
> the "make install" target of the swupdate Makefile. The service files
> which are not used for the latest git version of swupdate are moved
> to swupdate-2019.04 folder.
> 
> Fixes in do_install
> - This changes the filenames of the tools binaries for several reasons:
>   - Binaries should not be named "client" or "progress"
>     (also not accepted by Debian upstream)
>   - Inconsistent with names referred in the service files
> - The swupdate_tools.inc file gets merged into swupdate.inc file. By
>   removing the tools file some bugs are fixed:
>   - The tools binaries were installed twice.
>   - do_compile from swupdate.inc was over written resulting in wired
>     behavior
>   - swupdate-progress.service file was part of swupdate package were
>     the corresponding swupdate-progress binary was part of the tools
>     package.
> 
> Improve package splitting
> - New packages are: swupdate-client, swupdate-progress, swupdate-usb,
>   swupdate-tools-hawkbit.
> - Additionally swupdate-sd, swupdate-sv, swupdate-usb-sd and
>   swupdate-progress-sd have been introduced. The purpose of the -sd
>   and -sv packages is to provide the systemd service files or the
>   sysv init scripts. Splitting the init scripts and service files is
>   very atypical for Yocto, but it offers the flexibility to build a
>   second minimal rescue image with sysv, just capable to run swupdate,
>   out of the same DISTRO.
>   By default (if not changed by a bbappend file) the rdepends are
>   set e.g. from swupdate-usb to swupdate-sd, if systemd is enabled.
> - The swupdate-tools package is an empty meta package now. It provides
>   backward compatibility for setups installing swupdate-tools. It
>   depends on swupdate-client, swupdate-progress, swupdate-usb,
>   swupdate-tools-hawkbit packages.
> 
> Remove the INSANE_SKIP_${PN} = "ldflags". Seems obsolete.
> 
> Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
> ---
>  .../swupdate-progress.service                      |  0
>  .../swupdate-usb.rules                             |  0
>  .../swupdate-usb@.service                          |  0
>  .../swupdate.service                               |  0
>  .../systemd-tmpfiles-swupdate.conf                 |  0
>  recipes-support/swupdate/swupdate.inc              | 98 +++++++++++++++-------
>  recipes-support/swupdate/swupdate_2019.04.bb       | 28 ++++++-
>  recipes-support/swupdate/swupdate_git.bb           |  5 +-
>  recipes-support/swupdate/swupdate_tools.inc        | 24 ------
>  9 files changed, 97 insertions(+), 58 deletions(-)
>  rename recipes-support/swupdate/{swupdate => swupdate-2019.04}/swupdate-progress.service (100%)
>  rename recipes-support/swupdate/{swupdate => swupdate-2019.04}/swupdate-usb.rules (100%)
>  rename recipes-support/swupdate/{swupdate => swupdate-2019.04}/swupdate-usb@.service (100%)
>  rename recipes-support/swupdate/{swupdate => swupdate-2019.04}/swupdate.service (100%)
>  rename recipes-support/swupdate/{swupdate => swupdate-2019.04}/systemd-tmpfiles-swupdate.conf (100%)
>  delete mode 100644 recipes-support/swupdate/swupdate_tools.inc
> 
> diff --git a/recipes-support/swupdate/swupdate/swupdate-progress.service b/recipes-support/swupdate/swupdate-2019.04/swupdate-progress.service
> similarity index 100%
> rename from recipes-support/swupdate/swupdate/swupdate-progress.service
> rename to recipes-support/swupdate/swupdate-2019.04/swupdate-progress.service
> diff --git a/recipes-support/swupdate/swupdate/swupdate-usb.rules b/recipes-support/swupdate/swupdate-2019.04/swupdate-usb.rules
> similarity index 100%
> rename from recipes-support/swupdate/swupdate/swupdate-usb.rules
> rename to recipes-support/swupdate/swupdate-2019.04/swupdate-usb.rules
> diff --git a/recipes-support/swupdate/swupdate/swupdate-usb@.service b/recipes-support/swupdate/swupdate-2019.04/swupdate-usb@.service
> similarity index 100%
> rename from recipes-support/swupdate/swupdate/swupdate-usb@.service
> rename to recipes-support/swupdate/swupdate-2019.04/swupdate-usb@.service
> diff --git a/recipes-support/swupdate/swupdate/swupdate.service b/recipes-support/swupdate/swupdate-2019.04/swupdate.service
> similarity index 100%
> rename from recipes-support/swupdate/swupdate/swupdate.service
> rename to recipes-support/swupdate/swupdate-2019.04/swupdate.service
> diff --git a/recipes-support/swupdate/swupdate/systemd-tmpfiles-swupdate.conf b/recipes-support/swupdate/swupdate-2019.04/systemd-tmpfiles-swupdate.conf
> similarity index 100%
> rename from recipes-support/swupdate/swupdate/systemd-tmpfiles-swupdate.conf
> rename to recipes-support/swupdate/swupdate-2019.04/systemd-tmpfiles-swupdate.conf
> diff --git a/recipes-support/swupdate/swupdate.inc b/recipes-support/swupdate/swupdate.inc
> index 392af31..238d96a 100644
> --- a/recipes-support/swupdate/swupdate.inc
> +++ b/recipes-support/swupdate/swupdate.inc
> @@ -10,19 +10,53 @@ inherit cml1 update-rc.d systemd pkgconfig
>  SRC_URI = "git://github.com/sbabic/swupdate.git;protocol=https \
>       file://defconfig \
>       file://swupdate \
> -     file://swupdate.service \
> -     file://swupdate-usb.rules \
> -     file://swupdate-usb@.service \
> -     file://swupdate-progress.service \
> -     file://systemd-tmpfiles-swupdate.conf \
>       "
>  
> -INSANE_SKIP_${PN} = "ldflags"
> -PACKAGES =+ "${PN}-www ${PN}-lua"
> -
> +PACKAGES =+ " \
> +    ${PN}-client \
> +    ${PN}-lua \
> +    ${PN}-progress \
> +    ${PN}-progress-sd \
> +    ${PN}-sd \
> +    ${PN}-sv \
> +    ${PN}-tools \
> +    ${PN}-tools-hawkbit \
> +    ${PN}-usb \
> +    ${PN}-usb-sd \
> +    ${PN}-www \
> +"
> +
> +FILES_${PN}-client = "${bindir}/swupdate-client"
>  FILES_${PN}-lua += "${libdir}/lua/"
> -FILES_${PN}-www = "/www/*"
> -FILES_${PN} += "${libdir}/tmpfiles.d"
> +FILES_${PN}-progress = "${bindir}/swupdate-progress"
> +FILES_${PN}-progress-sd = "${systemd_system_unitdir}/swupdate-progress.service"
> +FILES_${PN}-sd = " \
> +    ${systemd_system_unitdir}/swupdate.socket \
> +    ${systemd_system_unitdir}/swupdate.service \
> +"
> +FILES_${PN}-sv = "${sysconfdir}/init.d/*"
> +FILES_${PN}-usb = "${sysconfdir}/udev/rules.d/swupdate-usb.rules"
> +FILES_${PN}-usb-sd = "${systemd_system_unitdir}/swupdate-usb@.service"
> +FILES_${PN}-tools-hawkbit = " \
> +    ${bindir}/swupdate-hawkbitcfg \
> +    ${bindir}/swupdate-sendtohawkbit \
> +"
> +FILES_${PN} += " \
> +    ${libdir}/tmpfiles.d \
> +    ${libdir}/swupdate/* \
> +"
> +FILES_${PN}-www = " \
> +    ${libdir}/swupdate/conf.d/*mongoose* \
> +    /www/* \
> +"
> +
> +RDEPENDS_${PN}-progress += "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'swupdate-progress-sd', '', d)}"
> +RDEPENDS_${PN}-usb += "${PN}-client ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'swupdate-usb-sd', '', d)}"
> +RDEPENDS_${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'swupdate-sd', 'swupdate-sv', d)}"
> +
> +# The tools package is deprecated, it is an empty meta package for backward compatibility
> +RDEPENDS_${PN}-tools += "${PN}-client ${PN}-progress ${PN}-tools-hawkbit ${PN}-usb"
> +
>  
>  S = "${WORKDIR}/git/"
>  
> @@ -116,17 +150,20 @@ python () {
>  }
>  
>  do_configure () {
> -  cp ${WORKDIR}/defconfig ${S}/.config
> -  merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
> -  cml1_do_configure
> +    # Always install systemd support and the swupdate.sh shell wrapper.
> +    # This allows to build swupdate packages init manager agnostic and splitt the file to separate packages.
> +    grep -v 'CONFIG_SYSTEMD' ${WORKDIR}/defconfig > ${S}/.config
> +    echo "# Global settings from swupdate recipe" >> ${S}/.config
> +    echo "CONFIG_SYSTEMD=y" >> ${S}/.config
> +    echo "CONFIG_SYSTEMD_SYSTEM_UNITDIR=\"${systemd_system_unitdir}\"" >> ${S}/.config
> +

With this, SWUpdate cannot be built. Suricatta includes header from
systemd and because systemd is not in DEPENDS (and it cannot be because
there is no systemd on this device), compieler stops with error.

So I have currently set again do_configure() as before and I can build
clean. A deeper test I will do in next days, because on this device I
have replaced (as I am used to) the startup script with an own one.

The issue above can be solved on follow-up patch - at the moment, I am
glad to provide a clean build with current TOT and meta-swupdate.

Best regards,
Stefano


> +    merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
> +    cml1_do_configure
>  }
>  
>  do_compile() {
>    unset LDFLAGS
> -  oe_runmake swupdate_unstripped progress_unstripped
> -  cp swupdate_unstripped swupdate
> -  cp progress_unstripped progress
> -
> +  oe_runmake
>  }
>  
>  do_install () {
> @@ -142,23 +179,20 @@ do_install () {
>  
>    install -d ${D}${sysconfdir}/init.d
>    install -m 755 ${WORKDIR}/swupdate ${D}${sysconfdir}/init.d
> -
> -  install -d ${D}${systemd_unitdir}/system
> -  install -m 644 ${WORKDIR}/swupdate.service ${D}${systemd_unitdir}/system
> -  install -m 644 ${WORKDIR}/swupdate-usb@.service ${D}${systemd_unitdir}/system
> -  install -m 644 ${WORKDIR}/swupdate-progress.service ${D}${systemd_unitdir}/system
> -
> -
> -  if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
> -    install -d ${D}${libdir}/tmpfiles.d
> -    install -m 0644 ${WORKDIR}/systemd-tmpfiles-swupdate.conf ${D}${libdir}/tmpfiles.d/swupdate.conf
> -    install -d ${D}${sysconfdir}/udev/rules.d
> -    install -m 0644 ${WORKDIR}/swupdate-usb.rules ${D}${sysconfdir}/udev/rules.d/
> -  fi
>  }
>  
>  INITSCRIPT_NAME = "swupdate"
>  INITSCRIPT_PARAMS = "defaults 70"
>  
> -SYSTEMD_SERVICE_${PN} = "swupdate.service"
> -SYSTEMD_SERVICE_${PN} += "swupdate-usb@.service swupdate-progress.service"
> +SYSTEMD_PACKAGES_append = " ${PN}-sd ${PN}-progress-sd ${PN}-usb-sd"
> +SYSTEMD_SERVICE_${PN}-sd = "swupdate.service"
> +SYSTEMD_SERVICE_${PN}-progress-sd = "swupdate-progress.service"
> +SYSTEMD_SERVICE_${PN}-usb-sd = "swupdate-usb@.service"
> +
> +# Prevents the systemd.bbclass from deleting scripts or service files.
> +rm_systemd_unitdir () {
> +    return 0
> +}
> +rm_sysvinit_initddir () {
> +    return 0
> +}
> diff --git a/recipes-support/swupdate/swupdate_2019.04.bb b/recipes-support/swupdate/swupdate_2019.04.bb
> index e2eabbb..5b0fb78 100644
> --- a/recipes-support/swupdate/swupdate_2019.04.bb
> +++ b/recipes-support/swupdate/swupdate_2019.04.bb
> @@ -1,4 +1,30 @@
>  require swupdate.inc
> -require swupdate_tools.inc
> +
> +SRC_URI += " \
> +     file://swupdate.service \
> +     file://swupdate-usb.rules \
> +     file://swupdate-usb@.service \
> +     file://swupdate-progress.service \
> +     file://systemd-tmpfiles-swupdate.conf \
> +     "
>  
>  SRCREV = "d39f4b8e00ef1929545b66158e45b82ea922bf81"
> +
> +do_install_append () {
> +    # Rename the binaries installed by make install
> +    test -f ${D}${bindir}/progress && mv ${D}${bindir}/progress ${D}${bindir}/swupdate-progress
> +    test -f ${D}${bindir}/client && mv ${D}${bindir}/client ${D}${bindir}/swupdate-client
> +    test -f ${D}${bindir}/hawkbitcfg && mv ${D}${bindir}/hawkbitcfg ${D}${bindir}/swupdate-hawkbitcfg
> +    test -f ${D}${bindir}/sendtohawkbit && mv ${D}${bindir}/sendtohawkbit ${D}${bindir}/swupdate-sendtohawkbit
> +
> +    install -d ${D}${systemd_system_unitdir}
> +    install -m 644 ${WORKDIR}/swupdate.service ${D}${systemd_system_unitdir}
> +    install -m 644 ${WORKDIR}/swupdate-usb@.service ${D}${systemd_system_unitdir}
> +    install -m 644 ${WORKDIR}/swupdate-progress.service ${D}${systemd_system_unitdir}
> +    if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
> +        install -d ${D}${libdir}/tmpfiles.d
> +        install -m 0644 ${WORKDIR}/systemd-tmpfiles-swupdate.conf ${D}${libdir}/tmpfiles.d/swupdate.conf
> +        install -d ${D}${sysconfdir}/udev/rules.d
> +        install -m 0644 ${WORKDIR}/swupdate-usb.rules ${D}${sysconfdir}/udev/rules.d/
> +    fi
> +}
> diff --git a/recipes-support/swupdate/swupdate_git.bb b/recipes-support/swupdate/swupdate_git.bb
> index 9fea83a..8eef04e 100644
> --- a/recipes-support/swupdate/swupdate_git.bb
> +++ b/recipes-support/swupdate/swupdate_git.bb
> @@ -1,7 +1,10 @@
>  require swupdate.inc
> -require swupdate_tools.inc
>  
>  DEFAULT_PREFERENCE = "-1"
>  
>  SRCREV ?= "045a618a725d0a2fce64161f10101c0004ac5d85"
>  PV = "2019.04+git${SRCPV}"
> +
> +SYSTEMD_SERVICE_${PN} += " \
> +    swupdate.socket \
> +"
> diff --git a/recipes-support/swupdate/swupdate_tools.inc b/recipes-support/swupdate/swupdate_tools.inc
> deleted file mode 100644
> index d270dd4..0000000
> --- a/recipes-support/swupdate/swupdate_tools.inc
> +++ /dev/null
> @@ -1,24 +0,0 @@
> -PACKAGES =+ "${PN}-tools"
> -
> -INSANE_SKIP_${PN}-tools = "ldflags"
> -
> -FILES_${PN}-tools = "${bindir}/swupdate-client \
> -                    ${bindir}/swupdate-progress \
> -                    ${bindir}/swupdate-hawkbitcfg \
> -                    ${bindir}/swupdate-sendtohawkbit"
> -
> -do_compile() {
> -  unset LDFLAGS
> -
> -  oe_runmake
> -  cp swupdate_unstripped swupdate
> -}
> -
> -do_install_append () {
> -
> -  install -m 0755 tools/client_unstripped ${D}${bindir}/swupdate-client
> -  install -m 0755 tools/progress_unstripped ${D}${bindir}/swupdate-progress
> -  install -m 0755 tools/hawkbitcfg_unstripped ${D}${bindir}/swupdate-hawkbitcfg
> -  install -m 0755 tools/sendtohawkbit_unstripped ${D}${bindir}/swupdate-sendtohawkbit
> -
> -}
>
diff mbox series

Patch

diff --git a/recipes-support/swupdate/swupdate/swupdate-progress.service b/recipes-support/swupdate/swupdate-2019.04/swupdate-progress.service
similarity index 100%
rename from recipes-support/swupdate/swupdate/swupdate-progress.service
rename to recipes-support/swupdate/swupdate-2019.04/swupdate-progress.service
diff --git a/recipes-support/swupdate/swupdate/swupdate-usb.rules b/recipes-support/swupdate/swupdate-2019.04/swupdate-usb.rules
similarity index 100%
rename from recipes-support/swupdate/swupdate/swupdate-usb.rules
rename to recipes-support/swupdate/swupdate-2019.04/swupdate-usb.rules
diff --git a/recipes-support/swupdate/swupdate/swupdate-usb@.service b/recipes-support/swupdate/swupdate-2019.04/swupdate-usb@.service
similarity index 100%
rename from recipes-support/swupdate/swupdate/swupdate-usb@.service
rename to recipes-support/swupdate/swupdate-2019.04/swupdate-usb@.service
diff --git a/recipes-support/swupdate/swupdate/swupdate.service b/recipes-support/swupdate/swupdate-2019.04/swupdate.service
similarity index 100%
rename from recipes-support/swupdate/swupdate/swupdate.service
rename to recipes-support/swupdate/swupdate-2019.04/swupdate.service
diff --git a/recipes-support/swupdate/swupdate/systemd-tmpfiles-swupdate.conf b/recipes-support/swupdate/swupdate-2019.04/systemd-tmpfiles-swupdate.conf
similarity index 100%
rename from recipes-support/swupdate/swupdate/systemd-tmpfiles-swupdate.conf
rename to recipes-support/swupdate/swupdate-2019.04/systemd-tmpfiles-swupdate.conf
diff --git a/recipes-support/swupdate/swupdate.inc b/recipes-support/swupdate/swupdate.inc
index 392af31..238d96a 100644
--- a/recipes-support/swupdate/swupdate.inc
+++ b/recipes-support/swupdate/swupdate.inc
@@ -10,19 +10,53 @@  inherit cml1 update-rc.d systemd pkgconfig
 SRC_URI = "git://github.com/sbabic/swupdate.git;protocol=https \
      file://defconfig \
      file://swupdate \
-     file://swupdate.service \
-     file://swupdate-usb.rules \
-     file://swupdate-usb@.service \
-     file://swupdate-progress.service \
-     file://systemd-tmpfiles-swupdate.conf \
      "
 
-INSANE_SKIP_${PN} = "ldflags"
-PACKAGES =+ "${PN}-www ${PN}-lua"
-
+PACKAGES =+ " \
+    ${PN}-client \
+    ${PN}-lua \
+    ${PN}-progress \
+    ${PN}-progress-sd \
+    ${PN}-sd \
+    ${PN}-sv \
+    ${PN}-tools \
+    ${PN}-tools-hawkbit \
+    ${PN}-usb \
+    ${PN}-usb-sd \
+    ${PN}-www \
+"
+
+FILES_${PN}-client = "${bindir}/swupdate-client"
 FILES_${PN}-lua += "${libdir}/lua/"
-FILES_${PN}-www = "/www/*"
-FILES_${PN} += "${libdir}/tmpfiles.d"
+FILES_${PN}-progress = "${bindir}/swupdate-progress"
+FILES_${PN}-progress-sd = "${systemd_system_unitdir}/swupdate-progress.service"
+FILES_${PN}-sd = " \
+    ${systemd_system_unitdir}/swupdate.socket \
+    ${systemd_system_unitdir}/swupdate.service \
+"
+FILES_${PN}-sv = "${sysconfdir}/init.d/*"
+FILES_${PN}-usb = "${sysconfdir}/udev/rules.d/swupdate-usb.rules"
+FILES_${PN}-usb-sd = "${systemd_system_unitdir}/swupdate-usb@.service"
+FILES_${PN}-tools-hawkbit = " \
+    ${bindir}/swupdate-hawkbitcfg \
+    ${bindir}/swupdate-sendtohawkbit \
+"
+FILES_${PN} += " \
+    ${libdir}/tmpfiles.d \
+    ${libdir}/swupdate/* \
+"
+FILES_${PN}-www = " \
+    ${libdir}/swupdate/conf.d/*mongoose* \
+    /www/* \
+"
+
+RDEPENDS_${PN}-progress += "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'swupdate-progress-sd', '', d)}"
+RDEPENDS_${PN}-usb += "${PN}-client ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'swupdate-usb-sd', '', d)}"
+RDEPENDS_${PN} += "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'swupdate-sd', 'swupdate-sv', d)}"
+
+# The tools package is deprecated, it is an empty meta package for backward compatibility
+RDEPENDS_${PN}-tools += "${PN}-client ${PN}-progress ${PN}-tools-hawkbit ${PN}-usb"
+
 
 S = "${WORKDIR}/git/"
 
@@ -116,17 +150,20 @@  python () {
 }
 
 do_configure () {
-  cp ${WORKDIR}/defconfig ${S}/.config
-  merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
-  cml1_do_configure
+    # Always install systemd support and the swupdate.sh shell wrapper.
+    # This allows to build swupdate packages init manager agnostic and splitt the file to separate packages.
+    grep -v 'CONFIG_SYSTEMD' ${WORKDIR}/defconfig > ${S}/.config
+    echo "# Global settings from swupdate recipe" >> ${S}/.config
+    echo "CONFIG_SYSTEMD=y" >> ${S}/.config
+    echo "CONFIG_SYSTEMD_SYSTEM_UNITDIR=\"${systemd_system_unitdir}\"" >> ${S}/.config
+
+    merge_config.sh -m .config ${@" ".join(find_cfgs(d))}
+    cml1_do_configure
 }
 
 do_compile() {
   unset LDFLAGS
-  oe_runmake swupdate_unstripped progress_unstripped
-  cp swupdate_unstripped swupdate
-  cp progress_unstripped progress
-
+  oe_runmake
 }
 
 do_install () {
@@ -142,23 +179,20 @@  do_install () {
 
   install -d ${D}${sysconfdir}/init.d
   install -m 755 ${WORKDIR}/swupdate ${D}${sysconfdir}/init.d
-
-  install -d ${D}${systemd_unitdir}/system
-  install -m 644 ${WORKDIR}/swupdate.service ${D}${systemd_unitdir}/system
-  install -m 644 ${WORKDIR}/swupdate-usb@.service ${D}${systemd_unitdir}/system
-  install -m 644 ${WORKDIR}/swupdate-progress.service ${D}${systemd_unitdir}/system
-
-
-  if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
-    install -d ${D}${libdir}/tmpfiles.d
-    install -m 0644 ${WORKDIR}/systemd-tmpfiles-swupdate.conf ${D}${libdir}/tmpfiles.d/swupdate.conf
-    install -d ${D}${sysconfdir}/udev/rules.d
-    install -m 0644 ${WORKDIR}/swupdate-usb.rules ${D}${sysconfdir}/udev/rules.d/
-  fi
 }
 
 INITSCRIPT_NAME = "swupdate"
 INITSCRIPT_PARAMS = "defaults 70"
 
-SYSTEMD_SERVICE_${PN} = "swupdate.service"
-SYSTEMD_SERVICE_${PN} += "swupdate-usb@.service swupdate-progress.service"
+SYSTEMD_PACKAGES_append = " ${PN}-sd ${PN}-progress-sd ${PN}-usb-sd"
+SYSTEMD_SERVICE_${PN}-sd = "swupdate.service"
+SYSTEMD_SERVICE_${PN}-progress-sd = "swupdate-progress.service"
+SYSTEMD_SERVICE_${PN}-usb-sd = "swupdate-usb@.service"
+
+# Prevents the systemd.bbclass from deleting scripts or service files.
+rm_systemd_unitdir () {
+    return 0
+}
+rm_sysvinit_initddir () {
+    return 0
+}
diff --git a/recipes-support/swupdate/swupdate_2019.04.bb b/recipes-support/swupdate/swupdate_2019.04.bb
index e2eabbb..5b0fb78 100644
--- a/recipes-support/swupdate/swupdate_2019.04.bb
+++ b/recipes-support/swupdate/swupdate_2019.04.bb
@@ -1,4 +1,30 @@ 
 require swupdate.inc
-require swupdate_tools.inc
+
+SRC_URI += " \
+     file://swupdate.service \
+     file://swupdate-usb.rules \
+     file://swupdate-usb@.service \
+     file://swupdate-progress.service \
+     file://systemd-tmpfiles-swupdate.conf \
+     "
 
 SRCREV = "d39f4b8e00ef1929545b66158e45b82ea922bf81"
+
+do_install_append () {
+    # Rename the binaries installed by make install
+    test -f ${D}${bindir}/progress && mv ${D}${bindir}/progress ${D}${bindir}/swupdate-progress
+    test -f ${D}${bindir}/client && mv ${D}${bindir}/client ${D}${bindir}/swupdate-client
+    test -f ${D}${bindir}/hawkbitcfg && mv ${D}${bindir}/hawkbitcfg ${D}${bindir}/swupdate-hawkbitcfg
+    test -f ${D}${bindir}/sendtohawkbit && mv ${D}${bindir}/sendtohawkbit ${D}${bindir}/swupdate-sendtohawkbit
+
+    install -d ${D}${systemd_system_unitdir}
+    install -m 644 ${WORKDIR}/swupdate.service ${D}${systemd_system_unitdir}
+    install -m 644 ${WORKDIR}/swupdate-usb@.service ${D}${systemd_system_unitdir}
+    install -m 644 ${WORKDIR}/swupdate-progress.service ${D}${systemd_system_unitdir}
+    if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)}; then
+        install -d ${D}${libdir}/tmpfiles.d
+        install -m 0644 ${WORKDIR}/systemd-tmpfiles-swupdate.conf ${D}${libdir}/tmpfiles.d/swupdate.conf
+        install -d ${D}${sysconfdir}/udev/rules.d
+        install -m 0644 ${WORKDIR}/swupdate-usb.rules ${D}${sysconfdir}/udev/rules.d/
+    fi
+}
diff --git a/recipes-support/swupdate/swupdate_git.bb b/recipes-support/swupdate/swupdate_git.bb
index 9fea83a..8eef04e 100644
--- a/recipes-support/swupdate/swupdate_git.bb
+++ b/recipes-support/swupdate/swupdate_git.bb
@@ -1,7 +1,10 @@ 
 require swupdate.inc
-require swupdate_tools.inc
 
 DEFAULT_PREFERENCE = "-1"
 
 SRCREV ?= "045a618a725d0a2fce64161f10101c0004ac5d85"
 PV = "2019.04+git${SRCPV}"
+
+SYSTEMD_SERVICE_${PN} += " \
+    swupdate.socket \
+"
diff --git a/recipes-support/swupdate/swupdate_tools.inc b/recipes-support/swupdate/swupdate_tools.inc
deleted file mode 100644
index d270dd4..0000000
--- a/recipes-support/swupdate/swupdate_tools.inc
+++ /dev/null
@@ -1,24 +0,0 @@ 
-PACKAGES =+ "${PN}-tools"
-
-INSANE_SKIP_${PN}-tools = "ldflags"
-
-FILES_${PN}-tools = "${bindir}/swupdate-client \
-                    ${bindir}/swupdate-progress \
-                    ${bindir}/swupdate-hawkbitcfg \
-                    ${bindir}/swupdate-sendtohawkbit"
-
-do_compile() {
-  unset LDFLAGS
-
-  oe_runmake
-  cp swupdate_unstripped swupdate
-}
-
-do_install_append () {
-
-  install -m 0755 tools/client_unstripped ${D}${bindir}/swupdate-client
-  install -m 0755 tools/progress_unstripped ${D}${bindir}/swupdate-progress
-  install -m 0755 tools/hawkbitcfg_unstripped ${D}${bindir}/swupdate-hawkbitcfg
-  install -m 0755 tools/sendtohawkbit_unstripped ${D}${bindir}/swupdate-sendtohawkbit
-
-}