From df95f956b6195fe4b5d1a21a59c764ccd64aa05a Mon Sep 17 00:00:00 2001 From: Martin Schwan Date: Thu, 23 Oct 2025 11:46:36 +0200 Subject: [PATCH] thingsboard-gateway: Update systemd service Update the systemd service file to reflect the changes of the source repository. Add a user and group "thingsboard_gateway" which the service runs under, instead of root. Store temporary files, like logs, in /var and make use of the newly created user and group. Additionally, the service should start after and wants a network connection to be online, not just be activated. Signed-off-by: Martin Schwan Signed-off-by: Khem Raj --- .../thingsboard-gateway.service | 18 ++++++++------ .../thingsboard-gateway_3.7.4.bb | 24 ++++++++++++++++--- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/meta-oe/dynamic-layers/meta-python/recipes-connectivity/thingsboard-gateway/thingsboard-gateway/thingsboard-gateway.service b/meta-oe/dynamic-layers/meta-python/recipes-connectivity/thingsboard-gateway/thingsboard-gateway/thingsboard-gateway.service index 5dd352a553..0b7601d494 100644 --- a/meta-oe/dynamic-layers/meta-python/recipes-connectivity/thingsboard-gateway/thingsboard-gateway/thingsboard-gateway.service +++ b/meta-oe/dynamic-layers/meta-python/recipes-connectivity/thingsboard-gateway/thingsboard-gateway/thingsboard-gateway.service @@ -1,13 +1,17 @@ [Unit] -Description = Systemd service for Thingsboard Gateway -After = network.target +Description=ThingsBoard Gateway +After=network-online.target +Wants=network-online.target +ConditionPathExists=/etc/thingsboard-gateway/config/tb_gateway.json [Service] -ExecStart = /usr/bin/python3 /usr/bin/thingsboard-gateway -ExecStop = /bin/kill -INT $MAINPID -ExecReload = /bin/kill -TERM $MAINPID -Restart = always -Type = simple +Type=simple +User=thingsboard_gateway +Group=thingsboard_gateway +ExecStart=/usr/bin/python3 /usr/bin/thingsboard-gateway +ExecStop=/bin/kill -INT $MAINPID +ExecReload=/bin/kill -TERM $MAINPID +Restart=on-failure [Install] WantedBy=multi-user.target diff --git a/meta-oe/dynamic-layers/meta-python/recipes-connectivity/thingsboard-gateway/thingsboard-gateway_3.7.4.bb b/meta-oe/dynamic-layers/meta-python/recipes-connectivity/thingsboard-gateway/thingsboard-gateway_3.7.4.bb index 8ff06285f9..7a82414937 100644 --- a/meta-oe/dynamic-layers/meta-python/recipes-connectivity/thingsboard-gateway/thingsboard-gateway_3.7.4.bb +++ b/meta-oe/dynamic-layers/meta-python/recipes-connectivity/thingsboard-gateway/thingsboard-gateway_3.7.4.bb @@ -43,21 +43,39 @@ RDEPENDS:${PN} += " python3-jsonpath-rw \ SRC_URI += "file://thingsboard-gateway.service" - -inherit systemd +inherit systemd useradd SYSTEMD_PACKAGES = "${PN}" SYSTEMD_SERVICE:${PN} = "thingsboard-gateway.service" +USERADD_PACKAGES = "${PN}" +USERADD_PARAM:${PN} = " \ + --system --no-create-home \ + --comment 'ThingsBoard-Gateway Service' \ + --home-dir ${localstatedir}/lib/${BPN} \ + --shell ${base_sbindir}/nologin \ + --gid thingsboard_gateway thingsboard_gateway" +GROUPADD_PARAM:${PN} = "--system thingsboard_gateway" + FILES:${PN} += "/etc \ /lib \ /usr \ + ${localstatedir} \ " do_install:append(){ install -d ${D}${sysconfdir}/${BPN}/config install -m 0644 ${S}/thingsboard_gateway/config/*.json ${D}${sysconfdir}/${BPN}/config + chown -R thingsboard_gateway:thingsboard_gateway ${D}${sysconfdir}/${BPN} - install -d ${D}${systemd_unitdir}/system/ + install -d ${D}${systemd_system_unitdir}/ install -m 0644 ${UNPACKDIR}/thingsboard-gateway.service ${D}${systemd_system_unitdir}/thingsboard-gateway.service + + if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then + install -d ${D}${sysconfdir}/tmpfiles.d + echo "d ${localstatedir}/log/${BPN} 0755 thingsboard_gateway thingsboard_gateway -" \ + > ${D}${sysconfdir}/tmpfiles.d/${BPN}.conf + echo "d ${localstatedir}/lib/${BPN} 0755 thingsboard_gateway thingsboard_gateway -" \ + >> ${D}${sysconfdir}/tmpfiles.d/${BPN}.conf + fi }