From 51dbc0326a15786194195c2fdaac976cee705e86 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Fri, 13 Dec 2024 14:33:05 +0100 Subject: [PATCH 1/4] ignore whitespace entries in maintainer script generator --- .../_generated/c8y-firmware-plugin/apk/postinst | 1 - .../package_scripts/_generated/c8y-firmware-plugin/apk/postrm | 1 - .../_generated/c8y-remote-access-plugin/apk/postinst | 1 - .../_generated/c8y-remote-access-plugin/apk/postrm | 1 - .../package_scripts/_generated/tedge-agent/apk/postrm | 1 - .../package_scripts/_generated/tedge-mapper/apk/postinst | 4 ---- .../package_scripts/_generated/tedge-mapper/apk/postrm | 1 - .../package_scripts/_generated/tedge-watchdog/apk/postinst | 1 - .../package_scripts/_generated/tedge-watchdog/apk/postrm | 1 - configuration/package_scripts/generate.py | 2 ++ 10 files changed, 2 insertions(+), 12 deletions(-) diff --git a/configuration/package_scripts/_generated/c8y-firmware-plugin/apk/postinst b/configuration/package_scripts/_generated/c8y-firmware-plugin/apk/postinst index aa2813997b3..d37118bbe57 100644 --- a/configuration/package_scripts/_generated/c8y-firmware-plugin/apk/postinst +++ b/configuration/package_scripts/_generated/c8y-firmware-plugin/apk/postinst @@ -1,3 +1,2 @@ #!/bin/sh set -e - diff --git a/configuration/package_scripts/_generated/c8y-firmware-plugin/apk/postrm b/configuration/package_scripts/_generated/c8y-firmware-plugin/apk/postrm index aa2813997b3..d37118bbe57 100644 --- a/configuration/package_scripts/_generated/c8y-firmware-plugin/apk/postrm +++ b/configuration/package_scripts/_generated/c8y-firmware-plugin/apk/postrm @@ -1,3 +1,2 @@ #!/bin/sh set -e - diff --git a/configuration/package_scripts/_generated/c8y-remote-access-plugin/apk/postinst b/configuration/package_scripts/_generated/c8y-remote-access-plugin/apk/postinst index 43c60b9e8e9..3c485b9e5e8 100644 --- a/configuration/package_scripts/_generated/c8y-remote-access-plugin/apk/postinst +++ b/configuration/package_scripts/_generated/c8y-remote-access-plugin/apk/postinst @@ -3,6 +3,5 @@ set -e - ### Create supported operation files c8y-remote-access-plugin --init diff --git a/configuration/package_scripts/_generated/c8y-remote-access-plugin/apk/postrm b/configuration/package_scripts/_generated/c8y-remote-access-plugin/apk/postrm index aa2813997b3..d37118bbe57 100644 --- a/configuration/package_scripts/_generated/c8y-remote-access-plugin/apk/postrm +++ b/configuration/package_scripts/_generated/c8y-remote-access-plugin/apk/postrm @@ -1,3 +1,2 @@ #!/bin/sh set -e - diff --git a/configuration/package_scripts/_generated/tedge-agent/apk/postrm b/configuration/package_scripts/_generated/tedge-agent/apk/postrm index c078acd69a7..0f8f9d2ec47 100644 --- a/configuration/package_scripts/_generated/tedge-agent/apk/postrm +++ b/configuration/package_scripts/_generated/tedge-agent/apk/postrm @@ -40,4 +40,3 @@ case "$1" in esac - diff --git a/configuration/package_scripts/_generated/tedge-mapper/apk/postinst b/configuration/package_scripts/_generated/tedge-mapper/apk/postinst index bc16140509c..93bf3376ab8 100644 --- a/configuration/package_scripts/_generated/tedge-mapper/apk/postinst +++ b/configuration/package_scripts/_generated/tedge-mapper/apk/postinst @@ -3,10 +3,6 @@ set -e - - - - enable_start_service() { name="$1" diff --git a/configuration/package_scripts/_generated/tedge-mapper/apk/postrm b/configuration/package_scripts/_generated/tedge-mapper/apk/postrm index b86be925487..22ab312fff2 100644 --- a/configuration/package_scripts/_generated/tedge-mapper/apk/postrm +++ b/configuration/package_scripts/_generated/tedge-mapper/apk/postrm @@ -16,4 +16,3 @@ case "$1" in esac - diff --git a/configuration/package_scripts/_generated/tedge-watchdog/apk/postinst b/configuration/package_scripts/_generated/tedge-watchdog/apk/postinst index aa2813997b3..d37118bbe57 100644 --- a/configuration/package_scripts/_generated/tedge-watchdog/apk/postinst +++ b/configuration/package_scripts/_generated/tedge-watchdog/apk/postinst @@ -1,3 +1,2 @@ #!/bin/sh set -e - diff --git a/configuration/package_scripts/_generated/tedge-watchdog/apk/postrm b/configuration/package_scripts/_generated/tedge-watchdog/apk/postrm index aa2813997b3..d37118bbe57 100644 --- a/configuration/package_scripts/_generated/tedge-watchdog/apk/postrm +++ b/configuration/package_scripts/_generated/tedge-watchdog/apk/postrm @@ -1,3 +1,2 @@ #!/bin/sh set -e - diff --git a/configuration/package_scripts/generate.py b/configuration/package_scripts/generate.py index 412a03cc95c..32313ded931 100755 --- a/configuration/package_scripts/generate.py +++ b/configuration/package_scripts/generate.py @@ -88,6 +88,8 @@ def replace_variables( def write_script( input_contents, lines: List[str], output_file: Path, debug: bool = True ) -> str: + # filter out lines with only whitespace + lines = [line for line in lines if line.strip()] contents = replace_variables( input_contents, { From d54448e30a5e1c559fe42c7dd5bd7e546fdb2cc0 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Fri, 13 Dec 2024 14:34:34 +0100 Subject: [PATCH 2/4] add tedge-mapper systemd target definition to manage cloud profiles after package install/upgrade/removal --- .../init/systemd/tedge-mapper-aws.service | 2 +- .../init/systemd/tedge-mapper-aws.target | 5 ++ .../init/systemd/tedge-mapper-aws@.service | 3 +- .../init/systemd/tedge-mapper-az.target | 5 ++ .../init/systemd/tedge-mapper-az@.service | 1 + .../init/systemd/tedge-mapper-c8y.target | 5 ++ .../init/systemd/tedge-mapper-c8y@.service | 1 + .../package_manifests/nfpm.tedge-mapper.yaml | 33 ++++++++++ .../_generated/tedge-mapper/deb/postinst | 64 +++++++++++++++++++ .../_generated/tedge-mapper/deb/postrm | 6 +- .../_generated/tedge-mapper/deb/prerm | 2 +- .../_generated/tedge-mapper/rpm/postinst | 29 +++++++++ .../_generated/tedge-mapper/rpm/postrm | 2 +- .../_generated/tedge-mapper/rpm/prerm | 2 +- configuration/package_scripts/packages.json | 5 +- 15 files changed, 156 insertions(+), 9 deletions(-) create mode 100644 configuration/init/systemd/tedge-mapper-aws.target create mode 100644 configuration/init/systemd/tedge-mapper-az.target create mode 100644 configuration/init/systemd/tedge-mapper-c8y.target diff --git a/configuration/init/systemd/tedge-mapper-aws.service b/configuration/init/systemd/tedge-mapper-aws.service index 2077cb4cd7e..549b0bcc485 100644 --- a/configuration/init/systemd/tedge-mapper-aws.service +++ b/configuration/init/systemd/tedge-mapper-aws.service @@ -1,5 +1,5 @@ [Unit] -Description=tedge-mapper-aws checks Thin Edge JSON measurements and forwards to AWS IoT Hub. +Description=tedge-mapper-aws checks Thin Edge JSON measurements and forwards to AWS IoT Core. After=syslog.target network.target mosquitto.service [Service] diff --git a/configuration/init/systemd/tedge-mapper-aws.target b/configuration/init/systemd/tedge-mapper-aws.target new file mode 100644 index 00000000000..b3e342e9b06 --- /dev/null +++ b/configuration/init/systemd/tedge-mapper-aws.target @@ -0,0 +1,5 @@ +[Unit] +Description=tedge-mapper-aws cloud profile services + +[Install] +WantedBy=multi-user.target diff --git a/configuration/init/systemd/tedge-mapper-aws@.service b/configuration/init/systemd/tedge-mapper-aws@.service index 8c493f2c371..0ea9e357fd4 100644 --- a/configuration/init/systemd/tedge-mapper-aws@.service +++ b/configuration/init/systemd/tedge-mapper-aws@.service @@ -1,6 +1,7 @@ [Unit] -Description=tedge-mapper-aws checks Thin Edge JSON measurements and forwards to AWS IoT Hub. +Description=tedge-mapper-aws checks Thin Edge JSON measurements and forwards to AWS IoT Core. After=syslog.target network.target mosquitto.service +PartOf=tedge-mapper-aws.target [Service] User=tedge diff --git a/configuration/init/systemd/tedge-mapper-az.target b/configuration/init/systemd/tedge-mapper-az.target new file mode 100644 index 00000000000..37e750c13ea --- /dev/null +++ b/configuration/init/systemd/tedge-mapper-az.target @@ -0,0 +1,5 @@ +[Unit] +Description=tedge-mapper-az cloud profile services + +[Install] +WantedBy=multi-user.target diff --git a/configuration/init/systemd/tedge-mapper-az@.service b/configuration/init/systemd/tedge-mapper-az@.service index 578a80c168d..477d0381c41 100644 --- a/configuration/init/systemd/tedge-mapper-az@.service +++ b/configuration/init/systemd/tedge-mapper-az@.service @@ -1,6 +1,7 @@ [Unit] Description=tedge-mapper-az checks Thin Edge JSON measurements and forwards to Azure IoT Hub. After=syslog.target network.target mosquitto.service +PartOf=tedge-mapper-az.target [Service] User=tedge diff --git a/configuration/init/systemd/tedge-mapper-c8y.target b/configuration/init/systemd/tedge-mapper-c8y.target new file mode 100644 index 00000000000..6820f77daaa --- /dev/null +++ b/configuration/init/systemd/tedge-mapper-c8y.target @@ -0,0 +1,5 @@ +[Unit] +Description=tedge-mapper-c8y cloud profile services + +[Install] +WantedBy=multi-user.target diff --git a/configuration/init/systemd/tedge-mapper-c8y@.service b/configuration/init/systemd/tedge-mapper-c8y@.service index 8f332dbf14e..d47673c0788 100644 --- a/configuration/init/systemd/tedge-mapper-c8y@.service +++ b/configuration/init/systemd/tedge-mapper-c8y@.service @@ -1,6 +1,7 @@ [Unit] Description=tedge-mapper-c8y converts Thin Edge JSON measurements to Cumulocity JSON format. After=syslog.target network.target mosquitto.service +PartOf=tedge-mapper-c8y.target [Service] User=tedge diff --git a/configuration/package_manifests/nfpm.tedge-mapper.yaml b/configuration/package_manifests/nfpm.tedge-mapper.yaml index 359a3c8b1b1..a7cdc017919 100644 --- a/configuration/package_manifests/nfpm.tedge-mapper.yaml +++ b/configuration/package_manifests/nfpm.tedge-mapper.yaml @@ -44,6 +44,17 @@ contents: mode: 0644 packager: rpm + - src: ./configuration/init/systemd/tedge-mapper-aws.target + dst: /lib/systemd/system/tedge-mapper-aws.target + file_info: + mode: 0644 + packager: deb + - src: ./configuration/init/systemd/tedge-mapper-aws.target + dst: /lib/systemd/system/tedge-mapper-aws.target + file_info: + mode: 0644 + packager: rpm + - src: ./configuration/init/systemd/tedge-mapper-aws@.service dst: /lib/systemd/system/tedge-mapper-aws@.service file_info: @@ -66,6 +77,17 @@ contents: mode: 0644 packager: rpm + - src: ./configuration/init/systemd/tedge-mapper-az.target + dst: /lib/systemd/system/tedge-mapper-az.target + file_info: + mode: 0644 + packager: deb + - src: ./configuration/init/systemd/tedge-mapper-az.target + dst: /lib/systemd/system/tedge-mapper-az.target + file_info: + mode: 0644 + packager: rpm + - src: ./configuration/init/systemd/tedge-mapper-az@.service dst: /lib/systemd/system/tedge-mapper-az@.service file_info: @@ -88,6 +110,17 @@ contents: mode: 0644 packager: rpm + - src: ./configuration/init/systemd/tedge-mapper-c8y.target + dst: /lib/systemd/system/tedge-mapper-c8y.target + file_info: + mode: 0644 + packager: deb + - src: ./configuration/init/systemd/tedge-mapper-c8y.target + dst: /lib/systemd/system/tedge-mapper-c8y.target + file_info: + mode: 0644 + packager: rpm + - src: ./configuration/init/systemd/tedge-mapper-c8y@.service dst: /lib/systemd/system/tedge-mapper-c8y@.service file_info: diff --git a/configuration/package_scripts/_generated/tedge-mapper/deb/postinst b/configuration/package_scripts/_generated/tedge-mapper/deb/postinst index 96f2b05ff0c..4e766175e2e 100755 --- a/configuration/package_scripts/_generated/tedge-mapper/deb/postinst +++ b/configuration/package_scripts/_generated/tedge-mapper/deb/postinst @@ -70,6 +70,70 @@ if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-decon fi # End automatically added section # Automatically added by thin-edge.io +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + # This will only remove masks created by d-s-h on package removal. + deb-systemd-helper unmask tedge-mapper-aws.target >/dev/null || true + + # was-enabled defaults to true, so new installations run enable. + if deb-systemd-helper --quiet was-enabled tedge-mapper-aws.target; then + # Enables the unit on first installation, creates new + # symlinks on upgrades if the unit file has changed. + deb-systemd-helper enable tedge-mapper-aws.target >/dev/null || true + else + # Update the statefile to add new symlinks (if any), which need to be + # cleaned up on purge. Also remove old symlinks. + deb-systemd-helper update-state tedge-mapper-aws.target >/dev/null || true + fi +fi +# End automatically added section +# Automatically added by thin-edge.io +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + # This will only remove masks created by d-s-h on package removal. + deb-systemd-helper unmask tedge-mapper-az.target >/dev/null || true + + # was-enabled defaults to true, so new installations run enable. + if deb-systemd-helper --quiet was-enabled tedge-mapper-az.target; then + # Enables the unit on first installation, creates new + # symlinks on upgrades if the unit file has changed. + deb-systemd-helper enable tedge-mapper-az.target >/dev/null || true + else + # Update the statefile to add new symlinks (if any), which need to be + # cleaned up on purge. Also remove old symlinks. + deb-systemd-helper update-state tedge-mapper-az.target >/dev/null || true + fi +fi +# End automatically added section +# Automatically added by thin-edge.io +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + # This will only remove masks created by d-s-h on package removal. + deb-systemd-helper unmask tedge-mapper-c8y.target >/dev/null || true + + # was-enabled defaults to true, so new installations run enable. + if deb-systemd-helper --quiet was-enabled tedge-mapper-c8y.target; then + # Enables the unit on first installation, creates new + # symlinks on upgrades if the unit file has changed. + deb-systemd-helper enable tedge-mapper-c8y.target >/dev/null || true + else + # Update the statefile to add new symlinks (if any), which need to be + # cleaned up on purge. Also remove old symlinks. + deb-systemd-helper update-state tedge-mapper-c8y.target >/dev/null || true + fi +fi +# End automatically added section +# Automatically added by thin-edge.io +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then + if [ -d /run/systemd/system ]; then + systemctl --system daemon-reload >/dev/null || true + if [ -n "$2" ]; then + _dh_action=restart + else + _dh_action=start + fi + deb-systemd-invoke $_dh_action tedge-mapper-aws.target tedge-mapper-az.target tedge-mapper-c8y.target >/dev/null || true + fi +fi +# End automatically added section +# Automatically added by thin-edge.io if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then if [ -d /run/systemd/system ]; then systemctl --system daemon-reload >/dev/null || true diff --git a/configuration/package_scripts/_generated/tedge-mapper/deb/postrm b/configuration/package_scripts/_generated/tedge-mapper/deb/postrm index a2cd9a8d1a3..ebba3fc19ce 100755 --- a/configuration/package_scripts/_generated/tedge-mapper/deb/postrm +++ b/configuration/package_scripts/_generated/tedge-mapper/deb/postrm @@ -23,14 +23,14 @@ fi # Automatically added by thin-edge.io if [ "$1" = "remove" ]; then if [ -x "/usr/bin/deb-systemd-helper" ]; then - deb-systemd-helper mask tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service >/dev/null || true + deb-systemd-helper mask tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service tedge-mapper-aws.target tedge-mapper-az.target tedge-mapper-c8y.target >/dev/null || true fi fi if [ "$1" = "purge" ]; then if [ -x "/usr/bin/deb-systemd-helper" ]; then - deb-systemd-helper purge tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service >/dev/null || true - deb-systemd-helper unmask tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service >/dev/null || true + deb-systemd-helper purge tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service tedge-mapper-aws.target tedge-mapper-az.target tedge-mapper-c8y.target >/dev/null || true + deb-systemd-helper unmask tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service tedge-mapper-aws.target tedge-mapper-az.target tedge-mapper-c8y.target >/dev/null || true fi fi # End automatically added section diff --git a/configuration/package_scripts/_generated/tedge-mapper/deb/prerm b/configuration/package_scripts/_generated/tedge-mapper/deb/prerm index ca44c0ab455..48da30f607e 100755 --- a/configuration/package_scripts/_generated/tedge-mapper/deb/prerm +++ b/configuration/package_scripts/_generated/tedge-mapper/deb/prerm @@ -2,6 +2,6 @@ set -e # Automatically added by thin-edge.io if [ -d /run/systemd/system ] && [ "$1" = remove ]; then - deb-systemd-invoke stop tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service >/dev/null || true + deb-systemd-invoke stop tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service tedge-mapper-aws.target tedge-mapper-az.target tedge-mapper-c8y.target >/dev/null || true fi # End automatically added section \ No newline at end of file diff --git a/configuration/package_scripts/_generated/tedge-mapper/rpm/postinst b/configuration/package_scripts/_generated/tedge-mapper/rpm/postinst index afe45d6bb57..aa9f7a57a84 100644 --- a/configuration/package_scripts/_generated/tedge-mapper/rpm/postinst +++ b/configuration/package_scripts/_generated/tedge-mapper/rpm/postinst @@ -26,6 +26,35 @@ if [ $1 -eq 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then fi # End automatically added section # Automatically added by thin-edge.io +if [ $1 -eq 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then + # Initial installation + /usr/lib/systemd/systemd-update-helper install-system-units tedge-mapper-aws.target || : +fi +# End automatically added section +# Automatically added by thin-edge.io +if [ $1 -eq 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then + # Initial installation + /usr/lib/systemd/systemd-update-helper install-system-units tedge-mapper-az.target || : +fi +# End automatically added section +# Automatically added by thin-edge.io +if [ $1 -eq 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then + # Initial installation + /usr/lib/systemd/systemd-update-helper install-system-units tedge-mapper-c8y.target || : +fi +# End automatically added section +# Automatically added by thin-edge.io +if [ -d /run/systemd/system ]; then + systemctl --system daemon-reload >/dev/null || true + if [ $1 -eq 2 ]; then + _dh_action=restart + else + _dh_action=start + fi + systemctl $_dh_action tedge-mapper-aws.target tedge-mapper-az.target tedge-mapper-c8y.target >/dev/null || true +fi +# End automatically added section +# Automatically added by thin-edge.io if [ $1 -eq 2 ]; then if [ -d /run/systemd/system ]; then systemctl --system daemon-reload >/dev/null || true diff --git a/configuration/package_scripts/_generated/tedge-mapper/rpm/postrm b/configuration/package_scripts/_generated/tedge-mapper/rpm/postrm index da05261eb56..7dad0257942 100644 --- a/configuration/package_scripts/_generated/tedge-mapper/rpm/postrm +++ b/configuration/package_scripts/_generated/tedge-mapper/rpm/postrm @@ -23,7 +23,7 @@ fi # Automatically added by thin-edge.io if [ $1 -ge 1 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then # Package upgrade, not uninstall - /usr/lib/systemd/systemd-update-helper mark-restart-system-units tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service || : + /usr/lib/systemd/systemd-update-helper mark-restart-system-units tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service tedge-mapper-aws.target tedge-mapper-az.target tedge-mapper-c8y.target || : fi # End automatically added section diff --git a/configuration/package_scripts/_generated/tedge-mapper/rpm/prerm b/configuration/package_scripts/_generated/tedge-mapper/rpm/prerm index 21ae7d4d00d..1ac2a2ed0d9 100644 --- a/configuration/package_scripts/_generated/tedge-mapper/rpm/prerm +++ b/configuration/package_scripts/_generated/tedge-mapper/rpm/prerm @@ -3,6 +3,6 @@ set -e # Automatically added by thin-edge.io if [ $1 -eq 0 ] && [ -x "/usr/lib/systemd/systemd-update-helper" ]; then # Package removal, not upgrade - /usr/lib/systemd/systemd-update-helper remove-system-units tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service || : + /usr/lib/systemd/systemd-update-helper remove-system-units tedge-mapper-aws.service tedge-mapper-az.service tedge-mapper-c8y.service tedge-mapper-collectd.service tedge-mapper-aws.target tedge-mapper-az.target tedge-mapper-c8y.target || : fi # End automatically added section \ No newline at end of file diff --git a/configuration/package_scripts/packages.json b/configuration/package_scripts/packages.json index 8bab1ea5dee..6f1602f097a 100644 --- a/configuration/package_scripts/packages.json +++ b/configuration/package_scripts/packages.json @@ -35,7 +35,10 @@ {"name": "tedge-mapper-aws", "enable": false, "start": false, "restart_after_upgrade": true, "stop_on_upgrade": true}, {"name": "tedge-mapper-az", "enable": false, "start": false, "restart_after_upgrade": true, "stop_on_upgrade": true}, {"name": "tedge-mapper-c8y", "enable": false, "start": false, "restart_after_upgrade": true, "stop_on_upgrade": true}, - {"name": "tedge-mapper-collectd", "enable": false, "start": false, "restart_after_upgrade": true, "stop_on_upgrade": true} + {"name": "tedge-mapper-collectd", "enable": false, "start": false, "restart_after_upgrade": true, "stop_on_upgrade": true}, + {"name": "tedge-mapper-aws.target", "enable": true, "start": true, "restart_after_upgrade": true, "stop_on_upgrade": true}, + {"name": "tedge-mapper-az.target", "enable": true, "start": true, "restart_after_upgrade": true, "stop_on_upgrade": true}, + {"name": "tedge-mapper-c8y.target", "enable": true, "start": true, "restart_after_upgrade": true, "stop_on_upgrade": true} ] } } From fd6054d158d37bb9d711ba5820994dd999f2ed13 Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Fri, 13 Dec 2024 16:57:34 +0100 Subject: [PATCH 3/4] improve maintainer script generator for packages containing more than 1 service --- configuration/package_scripts/generate.py | 140 +++++++++++++--------- 1 file changed, 85 insertions(+), 55 deletions(-) diff --git a/configuration/package_scripts/generate.py b/configuration/package_scripts/generate.py index 32313ded931..1ddc96a7d74 100755 --- a/configuration/package_scripts/generate.py +++ b/configuration/package_scripts/generate.py @@ -106,7 +106,8 @@ def write_script( output_file.write_text(contents, encoding="utf8") return contents -def format_unit_name(name: str, default_suffix = ".service") -> str: + +def format_unit_name(name: str, default_suffix=".service") -> str: if "." not in name: return name + default_suffix return name @@ -120,7 +121,9 @@ def process_package(name: str, manifest: dict, package_type: str, out_dir: Path) prerm = [] postrm = [] - service_names = [format_unit_name((service.name or name), ".service") for service in services] + service_names = [ + format_unit_name((service.name or name), ".service") for service in services + ] log.info("Processing package: %s, type=%s", name, package_type) variables = { @@ -157,7 +160,33 @@ def process_package(name: str, manifest: dict, package_type: str, out_dir: Path) ) ) - if service: + # + # Group services files based on their properties as they grouped to be executed as a single command + # The following template make use of UNITFILES, but since each package can contain multiple files + # the services functionality needs to be grouped. + # + if services: + # Helper + def append_matching_services( + script: List, template: str, predicate, variables: Dict + ): + matches = [ + format_unit_name((service.name or name), ".service") + for service in services + if predicate(service) + ] + if matches: + script.append( + replace_variables( + get_template(f"templates/{package_type}/{template}"), + { + **variables, + "UNITFILES": " ".join(matches), + }, + wrap=True, + ) + ) + # postrm postrm.append( replace_variables( @@ -167,64 +196,65 @@ def process_package(name: str, manifest: dict, package_type: str, out_dir: Path) ) ) + # postrm # Special case for rpm packages: # By default rpm maintainer scripts restart mark a service to be restarted in the postrm script # unlike debian which does this in the postinst. - if package_type != "rpm" or ( - service and package_type == "rpm" and service.stop_on_upgrade - ): - postrm.append( - replace_variables( - get_template(f"templates/{package_type}/postrm-systemd"), - variables, - wrap=True, - ) - ) - - if service.restart_after_upgrade: - snippet = { - True: ("postinst-systemd-restart", "restart"), - False: ("postinst-systemd-restartnostart", "try-restart"), - }[service.start] - - postinst.append( - replace_variables( - get_template(f"templates/{package_type}/{snippet[0]}"), - { - **variables, - "RESTART_ACTION": snippet[1], - }, - wrap=True, - ) + if package_type == "deb": + append_matching_services( + postrm, "postrm-systemd", lambda x: True, variables ) - elif service.start: - postinst.append( - replace_variables( - get_template(f"templates/{package_type}/postinst-systemd-start"), - variables, - wrap=True, - ) + elif package_type == "rpm": + append_matching_services( + postrm, "postrm-systemd", lambda x: service.stop_on_upgrade, variables ) - # prerm - if not service.stop_on_upgrade or service.restart_after_upgrade: - # stop service only on remove - prerm.append( - replace_variables( - get_template(f"templates/{package_type}/prerm-systemd-restart"), - variables, - wrap=True, - ) - ) - elif service.start: - # always stop service - prerm.append( - replace_variables( - get_template(f"templates/{package_type}/prerm-systemd"), - variables, - wrap=True, - ) - ) + ## postinst: restart after upgrade and start + append_matching_services( + postinst, + "postinst-systemd-restart", + lambda x: x.restart_after_upgrade and x.start, + { + **variables, + "RESTART_ACTION": "restart", + }, + ) + + ## postinst: restart after upgrade and no start + append_matching_services( + postinst, + "postinst-systemd-restartnostart", + lambda x: x.restart_after_upgrade and not x.start, + { + **variables, + "RESTART_ACTION": "try-restart", + }, + ) + + # postinst: restart_after_upgrade=false and start=true + append_matching_services( + postinst, + "postinst-systemd-start", + lambda x: not x.restart_after_upgrade and x.start, + variables, + ) + + # prerm: stop_on_upgrade=false or restart_after_upgrade=true + append_matching_services( + prerm, + "prerm-systemd-restart", + lambda x: not x.stop_on_upgrade or x.restart_after_upgrade, + variables, + ) + + # prerm: always stop service + append_matching_services( + prerm, + "prerm-systemd", + lambda x: not (not x.stop_on_upgrade or x.restart_after_upgrade) + and x.start, + variables, + ) # Default script contents if the script does not already exist default_t = "\n".join( From 03a544324618064fe648859c988289c28c37bb1d Mon Sep 17 00:00:00 2001 From: reubenmiller Date: Fri, 13 Dec 2024 16:59:23 +0100 Subject: [PATCH 4/4] test: check that tedge-mapper is restarted when upgrading package --- .../configuration_operation_multi_cloud.robot | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/RobotFramework/tests/cumulocity/configuration/configuration_operation_multi_cloud.robot b/tests/RobotFramework/tests/cumulocity/configuration/configuration_operation_multi_cloud.robot index c6cf88d65b1..599cc2b7bdc 100644 --- a/tests/RobotFramework/tests/cumulocity/configuration/configuration_operation_multi_cloud.robot +++ b/tests/RobotFramework/tests/cumulocity/configuration/configuration_operation_multi_cloud.robot @@ -26,6 +26,13 @@ Get Configuration from Second Device Text file topic_prefix=c8y-second external_id=${SECOND_DEVICE_SN} config_type=CONFIG1 device_file=/etc/config1.json Binary file topic_prefix=c8y-second external_id=${SECOND_DEVICE_SN} config_type=CONFIG1_BINARY device_file=/etc/binary-config1.tar.gz +Mapper Services Are Restarted After Updates + Cumulocity.Set Device ${DEVICE_SN} + ${pid_before}= Execute Command sudo systemctl show --property MainPID tedge-mapper-c8y@second + Execute Command dpkg -i packages/tedge-mapper*.deb + ${pid_after}= Execute Command sudo systemctl show --property MainPID tedge-mapper-c8y@second + Should Not Be Equal ${pid_before} ${pid_after} + *** Keywords *** Get Configuration from Device