flutter-apps-layer: add init service to automatically launch Flutter demo
This commit introduces a dynamic layer that extends the flutter-apps layer by adding an init service to automatically launch the Flutter demo on boot. https://onedigi.atlassian.net/browse/DEL-9380 Signed-off-by: Arturo Buzarra <arturo.buzarra@digi.com>
This commit is contained in:
parent
e09eff7e1a
commit
499ce2e97b
|
|
@ -28,6 +28,8 @@ BBFILES_DYNAMIC += " \
|
||||||
qt6-layer:${LAYERDIR}/dynamic-layers/qt6-layer/*/*/*.bbappend \
|
qt6-layer:${LAYERDIR}/dynamic-layers/qt6-layer/*/*/*.bbappend \
|
||||||
qt6-layer:${LAYERDIR}/dynamic-layers/qt6-layer/${DEY_SOC_VENDOR}/*/*/*.bb \
|
qt6-layer:${LAYERDIR}/dynamic-layers/qt6-layer/${DEY_SOC_VENDOR}/*/*/*.bb \
|
||||||
qt6-layer:${LAYERDIR}/dynamic-layers/qt6-layer/${DEY_SOC_VENDOR}/*/*/*.bbappend \
|
qt6-layer:${LAYERDIR}/dynamic-layers/qt6-layer/${DEY_SOC_VENDOR}/*/*/*.bbappend \
|
||||||
|
flutter-apps-layer:${LAYERDIR}/dynamic-layers/flutter-apps-layer/*/*/*/*.bb \
|
||||||
|
flutter-apps-layer:${LAYERDIR}/dynamic-layers/flutter-apps-layer/*/*/*/*.bbappend \
|
||||||
"
|
"
|
||||||
|
|
||||||
BBFILE_COLLECTIONS += "digi-dey"
|
BBFILE_COLLECTIONS += "digi-dey"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,111 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#===============================================================================
|
||||||
|
#
|
||||||
|
# Copyright (C) 2025 by Digi International Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of the GNU General Public License version 2 as published by
|
||||||
|
# the Free Software Foundation.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# !Description: Initialize Flutter demo
|
||||||
|
#
|
||||||
|
#===============================================================================
|
||||||
|
|
||||||
|
readonly DEMO_NAME="##FLUTTER_DEMO_NAME##"
|
||||||
|
readonly FLUTTER_VERSION="##FLUTTER_SDK_TAG##"
|
||||||
|
readonly FLUTTER_MODE="##FLUTTER_MODE##"
|
||||||
|
readonly DEMO_PATH="/usr/share/flutter/${DEMO_NAME}/${FLUTTER_VERSION}/${FLUTTER_MODE}/"
|
||||||
|
readonly DEMO_TITLE="Flutter Demo Application"
|
||||||
|
readonly PID_FILE="/run/${DEMO_NAME}.pid"
|
||||||
|
|
||||||
|
log() {
|
||||||
|
if type "systemd-cat" >/dev/null 2>/dev/null; then
|
||||||
|
systemd-cat -p "${1}" -t "${DEMO_NAME}" printf "%s" "${2}"
|
||||||
|
fi
|
||||||
|
logger -p "${1}" -t "${DEMO_NAME}" "${2}"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_demo_pid() {
|
||||||
|
local pid="$(pgrep -f ${DEMO_PATH})"
|
||||||
|
|
||||||
|
[ -n "${pid}" ] && { echo "${pid}"; return 0; }
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
check_is_running() {
|
||||||
|
local pid
|
||||||
|
|
||||||
|
if [ -s "${PID_FILE}" ]; then
|
||||||
|
pid="$(cat ${PID_FILE})"
|
||||||
|
else
|
||||||
|
pid="$(get_demo_pid)"
|
||||||
|
echo "${pid}" > ${PID_FILE}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${pid}" ]; then
|
||||||
|
kill -0 "${pid}" >/dev/null 2>&1 && return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f "${PID_FILE}"
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
check_is_running || return
|
||||||
|
|
||||||
|
local pid="$(cat ${PID_FILE})"
|
||||||
|
kill -TERM "${pid}" >/dev/null 2>&1
|
||||||
|
|
||||||
|
local STOP_TIMEOUT="5"
|
||||||
|
for i in $(seq ${STOP_TIMEOUT}); do
|
||||||
|
check_is_running || { log info "stopped"; break; }
|
||||||
|
if [ "${i}" -eq ${STOP_TIMEOUT} ]; then
|
||||||
|
log warning "stop: ${DEMO_NAME} did not stop gracefully"
|
||||||
|
kill -KILL "${pid}" >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
|
check_is_running && { log warning "start: ${DEMO_NAME} ALREADY running"; exit 0; }
|
||||||
|
|
||||||
|
# Launch demo
|
||||||
|
flutter-pi --release ${DEMO_PATH} >/dev/null 2>&1 &
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo $! > ${PID_FILE}
|
||||||
|
log info "$(cat ${PID_FILE})"
|
||||||
|
log info "started"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
echo -n "Starting ${DEMO_TITLE}: "
|
||||||
|
start
|
||||||
|
echo "done."
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
stop
|
||||||
|
echo -n "Stopping ${DEMO_TITLE}: "
|
||||||
|
if [ -n "`/bin/pidof ${DEMO_PATH}`" ] ; then
|
||||||
|
echo "FAIL"
|
||||||
|
else
|
||||||
|
echo "OK"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
stop
|
||||||
|
sleep 1
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: $0 {start|stop|restart}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Flutter Demo Application
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=forking
|
||||||
|
PIDFile=/run/##FLUTTER_DEMO_NAME##.pid
|
||||||
|
ExecStart=/etc/flutter-demo-init start
|
||||||
|
ExecStop=/etc/flutter-demo-init stop
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
# Copyright (C) 2025, Digi International Inc.
|
||||||
|
|
||||||
|
FILESEXTRAPATHS:prepend:dey := "${THISDIR}/files:"
|
||||||
|
|
||||||
|
SRC_URI:append = " \
|
||||||
|
file://flutter-demo-init \
|
||||||
|
file://flutter-demo-init.service \
|
||||||
|
"
|
||||||
|
|
||||||
|
FLUTTER_DEMO_NAME ?= "${PN}"
|
||||||
|
FLUTTER_MODE ?= "${FLUTTER_APP_RUNTIME_MODES}"
|
||||||
|
|
||||||
|
inherit update-rc.d systemd
|
||||||
|
|
||||||
|
do_install:append() {
|
||||||
|
# Install systemd service
|
||||||
|
if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
|
||||||
|
# Install systemd unit files
|
||||||
|
install -d ${D}${systemd_unitdir}/system
|
||||||
|
install -m 0644 ${WORKDIR}/flutter-demo-init.service ${D}${systemd_unitdir}/system/
|
||||||
|
sed -i -e "s,##FLUTTER_DEMO_NAME##,${FLUTTER_DEMO_NAME},g" \
|
||||||
|
"${D}${systemd_unitdir}/system/flutter-demo-init.service"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install wrapper bootscript to launch Flutter demo on boot
|
||||||
|
install -d ${D}${sysconfdir}/init.d
|
||||||
|
install -m 0755 ${WORKDIR}/flutter-demo-init ${D}${sysconfdir}/flutter-demo-init
|
||||||
|
ln -sf ${sysconfdir}/flutter-demo-init ${D}${sysconfdir}/init.d/flutter-demo-init
|
||||||
|
sed -i -e "s@##FLUTTER_SDK_TAG##@${FLUTTER_SDK_TAG}@g" \
|
||||||
|
-e "s@##FLUTTER_MODE##@${FLUTTER_MODE}@g" \
|
||||||
|
-e "s@##FLUTTER_DEMO_NAME##@${FLUTTER_DEMO_NAME}@g" \
|
||||||
|
"${D}${sysconfdir}/flutter-demo-init"
|
||||||
|
}
|
||||||
|
|
||||||
|
PACKAGES =+ "${PN}-init"
|
||||||
|
FILES:${PN}-init = " \
|
||||||
|
${sysconfdir}/flutter-demo-init \
|
||||||
|
${sysconfdir}/init.d/flutter-demo-init \
|
||||||
|
${systemd_unitdir}/system/flutter-demo-init.service \
|
||||||
|
"
|
||||||
|
|
||||||
|
INITSCRIPT_PACKAGES += "${PN}-init"
|
||||||
|
INITSCRIPT_NAME:${PN}-init = "flutter-demo-init"
|
||||||
|
INITSCRIPT_PARAMS:${PN}-init = "start 99 3 5 . stop 20 0 1 2 6 ."
|
||||||
|
|
||||||
|
SYSTEMD_PACKAGES = "${PN}-init"
|
||||||
|
SYSTEMD_SERVICE:${PN}-init = "flutter-demo-init.service"
|
||||||
|
|
@ -9,6 +9,7 @@ inherit packagegroup
|
||||||
RDEPENDS:${PN} += " \
|
RDEPENDS:${PN} += " \
|
||||||
flutter-pi \
|
flutter-pi \
|
||||||
flutter-samples-veggieseasons \
|
flutter-samples-veggieseasons \
|
||||||
|
flutter-samples-veggieseasons-init \
|
||||||
"
|
"
|
||||||
|
|
||||||
RDEPENDS:${PN}:append:imxgpu = " \
|
RDEPENDS:${PN}:append:imxgpu = " \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue