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 <m.schwan@phytec.de>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
This commit is contained in:
Martin Schwan 2025-10-23 11:46:36 +02:00 committed by Khem Raj
parent 5005e061ce
commit df95f956b6
2 changed files with 32 additions and 10 deletions

View File

@ -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

View File

@ -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
}