Why does autostart with systemd not work? - yocto

Yocto Version is warrior.
I did a yocto project with a GO/golang user app (https-server) that works just fine on a raspi3.
Now I'm trying to autostart it at the yocto image and doesnt't got it working.
I know there are plenty outher questions regarding this, but I didnt found something that helped.
e.g. I tried to follow all steps in this post
Enable systemd services using yocto
but it doesn't autostart at the raspi.
These files at the raspi for the service I found:
/lib/systemd/system/https-server.service
/etc/systemd/system/multi-user.target.wants/https-server.service
The application itself is running great if I start it manually,
it is at the raspi at /usr/bin/https-server
my build/conf/local.conf:
IMAGE_INSTALL_append = " kernel-image kernel-devicetree sudo apt dnsmasq nano dhcpcd git glibc-utils localedef curl go https-server"
meta-https-server/
├── conf
│   └── layer.conf
└── recipes-https-server
└── https-server
├── files
│   ├── https-server.go
│   ├── https-server.service
│   ├── mytest
│   ├── server.crt
│   ├── server.key
│   └── testvideo.mp4
├── go-sw.inc
└── https-server.bb
https-server.bb
require go-sw.inc
inherit go systemd
#inherit go update-rc.d systemd
SRC_URI += "file://https-server.service"
SRC_URI += "file://https-server.go"
SYSTEMD_PACKAGES = "${PN}"
INITSCRIPT_PACKAGES = "${PN}"
SYSTEMD_SERVICE_${PN} = "https-server.service"
# Path
MY_KEY = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/server.key"
MY_CERT = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/server.crt"
TESTVIDEO = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/testvideo.mp4"
MY_TEST = "/data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/mytest"
# COMPILER
do_compile() {
go build /data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/https-server.go
}
# INSTALL
do_install() {
# install -d to create directories, "${D}/${bindir}" is /usr/bin
# systemd
install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/https-server.service ${D}${systemd_unitdir}/system
# HTTPS certificate and key
install -d "${D}/${bindir}"
install -m 0755 "${MY_KEY}" "${D}/${bindir}"
install -m 0755 "${MY_CERT}" "${D}/${bindir}"
install -m 0777 "${TESTVIDEO}" "${D}/${bindir}"
install -m 0777 "${MY_TEST}" "${D}/${bindir}"
# HTTPS Server Software
install -m 0755 "${S}/build/https-server" "${D}/${bindir}"
}
FILES_${PN} += "${bindir}"
FILES_${PN} += "${libexecdir}"
FILES_${PN} += "${systemd_system_unitdir}"
REQUIRED_DISTRO_FEATURES= "systemd"
the service https-server.service
[Unit]
Description=HTTPS Server sw startup script
[Service]
ExecStart=/usr/bin/https-server
[Install]
WantedBy=multi-user.target

I found out what was causing the problem:
At my local configuration at build/conf/local.conf
I had only this:
DISTRO_FEATURES_append = " systemd "
after I added the following:
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = ""
It was working fine. The process https-server started at startup.
I checked the running processes after startup with ps, as
systemctl was not working on my core-image-minimal image:
root#raspberrypi3:~# ps
[...]
152 root 861m S /usr/bin/https-server
[...]
root#raspberrypi3:~#
So this made the difference. Don't know if the missing space at my
DISTRO_FEATURES_append = " systemd" was also wrong... ??
#DISTRO_FEATURES_append = " systemd"
DISTRO_FEATURES_append = " systemd "
DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit"
VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = ""
The oe-pkgdata-util that #Nayfe suggested is a very helpful tool here:
user#machine:[...]/poky-warrior/build$
oe-pkgdata-util list-pkg-files -p https-server
https-server:
/lib/systemd/system/https-server.service
/usr/bin/https-server
/usr/bin/mytest
/usr/bin/server.crt
/usr/bin/server.key
/usr/bin/testvideo.mp4
https-server-dbg:
/usr/bin/.debug/https-server
https-server-dev:
https-server-ptest:
I also worked over the recipe https-server.bb from above
to avoid absolute paths as #Nayfe suggested. This was not causing
the problem but it was bad style.
Don't use /data/yocto/2020-04-21-poky-warrior/poky-warrior/meta-https-server/recipes-https-server/https-server/files/ prefix, and add every files in SRC_URI instead.
require go-sw.inc
inherit go systemd
# "${D}/${bindir}" is /usr/bin
# ${WORKDIR} is path at local directory,
# this can be used instead of absolute paths
SRC_URI += "file://https-server.service"
SRC_URI += "file://https-server.go"
SRC_URI += "file://server.key"
SRC_URI += "file://server.crt"
SRC_URI += "file://testvideo.mp4"
SRC_URI += "file://mytest"
SYSTEMD_PACKAGES = "${PN}"
INITSCRIPT_PACKAGES = "${PN}"
SYSTEMD_SERVICE_${PN} = "https-server.service"
# COMPILER
do_compile() {
go build ${WORKDIR}/https-server.go
}
# INSTALL
do_install() {
# install -d to create directories, "${D}/${bindir}" is /usr/bin
# systemd
install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/https-server.service ${D}${systemd_unitdir}/system
# HTTPS certificate, key and testdata for https-server
install -d "${D}/${bindir}"
install -m 0755 ${WORKDIR}/server.key "${D}/${bindir}"
install -m 0755 ${WORKDIR}/server.crt "${D}/${bindir}"
install -m 0777 ${WORKDIR}/testvideo.mp4 "${D}/${bindir}"
install -m 0777 ${WORKDIR}/mytest "${D}/${bindir}"
# HTTPS Server Software
install -m 0755 "${WORKDIR}/build/https-server" "${D}/${bindir}"
}
# FILES_${PN} is Yocto’s way of specifying
# which files are expected to be installed along with which package
# (${PN} is a variable holding the main package’s name).
FILES_${PN} += "${bindir}"
FILES_${PN} += "${libexecdir}"
FILES_${PN} += "${systemd_system_unitdir}"
REQUIRED_DISTRO_FEATURES= "systemd"
Thanks to #kostix and #nayfe for their suggestions.

Related

Bitbake service file organization

I have a service created and working. However my current bitbake file makes my folder structure very ugly. To have it work I have to have all of my configuration files in my src folder. I would like to have two folders, src and configfiles.
If my tree is as follows
How can I edit my bb file to pull in my src directory and my configfiles?
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://src"
S = "${WORKDIR}/src"
CF = "${WORKDIR}/configfiles"
inherit systemd autotools
SYSTEMD_SERVICE_${PN} = "helloworld.service"
do_install_append () {
echo "look at this PN ${PN}"
echo "look at this D ${D}"
echo "look at this S ${S}"
echo "look at this CF ${CF}"
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${CF}/helloworld.service ${D}${systemd_system_unitdir}
sed -i -e 's,#BINDIR#,${bindir},g' ${D}${systemd_system_unitdir}/helloworld.service
}
Update 1:
I added a CF variable. Using bitbake -e helloworld > log.txt I can echo the values of variables and noticed we are not pointing to the config files.
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://src"
S = "${WORKDIR}/src"
CF = "${WORKDIR}/configfiles"
inherit systemd autotools
SYSTEMD_SERVICE_${PN} = "helloworld.service"
do_install_append () {
echo "look at this PN ${PN}"
echo "look at this D ${D}"
echo "look at this S ${S}"
echo "look at this CF ${CF}"
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${CF}/helloworld.service ${D}${systemd_system_unitdir}
sed -i -e 's,#BINDIR#,${bindir},g' ${D}${systemd_system_unitdir}/helloworld.service
}
Bitbake still can not find my makefile.
Update 2:
The solution given works but I have one more question.
My makefile is very basic:
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = foreign
SUBDIRS = app
CFLAGS = -Wall -pedantic
include_HEADERS = helloworld.h
bin_PROGRAMS = helloworld
helloworld_SOURCES = helloworld.c
I want to separate my files by folder. I want my main application in a folder /src/app. I edited my makefile to point to app/helloworld.h and app/helloworld.c However this does not find the files. My updated bb file follows
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
FILESEXTRAPATHS:prepend := "${THISDIR}/files/src:${THISDIR}/files/src/app:${THISDIR}/files/services:"
SRC_URI = "file://src \
file://src/app \
"
SRC_URI += "file://helloworld.service \
file://autogen.sh \
file://configure.ac \
file://Makefile.am"
S = "${WORKDIR}/src"
inherit systemd autotools
SYSTEMD_SERVICE_${PN} = "helloworld.service"
do_install_append () {
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/helloworld.service ${D}${systemd_system_unitdir}
sed -i -e 's,#BINDIR#,${bindir},g' ${D}${systemd_system_unitdir}/helloworld.service
}
I understand the makefile should be packaged with the code, This just does not work when creating larger applications.
You need to let bitbake know where to look for files, it sounds like you want to keep the Makefile in a separate directory but in most cases the Makefile should be with the source files, feel free to play around with this, the concept is still the same as explained below.
Either way, your directory structure should look something like this:
recipes-core/
helloworld/
helloworld_0.1.bb
files/
configfiles/
helloworld.service
src/
autogen.sh
configure.ac
helloworld.c
helloworld.h
Makefile.am
And to let bitbake know where to pull files you use the FILESESXTRAPATHS variable [1]:
FILESEXTRAPATHS:prepend := "${THISDIR}/files/src:${THISDIR}/files/configfiles:"
At this point bitbake knows WHERE to pull the files from, but it doesn't know which files to pull, for this you use the SRC_URI variable (specifically the file:// fetcher) [2]:
SRC_URI += "file://helloworld.service \
file://autogen.sh \
file://configure.ac \
file://helloworld.c \
file://helloworld.h \
file://Makefile.am"
This assumes your Makefile will try to find files in the same directory.
The rest of your recipe is fine, the CF variable is no longer necessary, and you just need to change where you're installing the service file from, since SRC_URI[1] will pull it to ${WORKDIR}:
install -m 0644 ${WORKDIR}/helloworld.service ${D}${systemd_system_unitdir}
[1] https://docs.yoctoproject.org/singleindex.html#term-FILESEXTRAPATHS
[2] https://docs.yoctoproject.org/bitbake/singleindex.html#term-SRC_URI

yocto recipe how to install file to rootfs

sorry I am a little new to syntax of yocto, this is how I have modified my recipe:
LICENSE = "LGPLv2.1"
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI = "file://myscript.sh"
FILES_${PN} += "${sysconfdir}/init.d/myscript.sh"
do_install() {
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/myscript.sh ${D}${sysconfdir}/init.d/
}
The recipe is added to the build, because if I remove the LICENSE line the yocto image will not be baked.
The folder where the recipe is kept is named "customssh", inside this folder I have the recipe named customssh_0.1.bb and a subfolder named "files" where the myscript.sh is kept.
After I have baked the image, I run this command to see if the myscript.sh has been placed in the rootfs:
find . -name 'myscript*'
which will return where the file is held:
./meta-swi/common/recipes-core/customssh/files/myscript.sh
In the recipe, is this line correct?
install -m 0755 ${WORKDIR}/myscript.sh ${D}${sysconfdir}/init.d/
If this is the root recipe and not a bbappend one use do_install instead of do_install_append
Make sure that ${D}${sysconfdir}/init.d is created before copying to it
do_install(){
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/myscript.sh ${D}${sysconfdir}/init.d/
}
Now, make sure to specify the file you installed so that the do_package will not fail
FILES_${PN} += "${sysconfdir}/init.d/myscript.sh"

Bitbake not installing files from recipe to rootfs

I'm currently using yocto to build the system imx6sxsabresd (IMX6 Solo X). I have successfully built the image however I want to add a script to init.d to turn on a led. I'm appending to the linux-imx recipes within the meta-fsl-bsp-release layer.
This is my linux-imx.bbappend file:
FILESEXTRAPATHS_prepend := "${THISDIR}/linux-imx:"
SRC_URI += "file://0001-added-pad-for-heartbeat-led.patch \
file://heartbeat.sh \
file://heartbeat "
PACKAGECONFIG_append = " heartbeat"
inherit update-rc.d
INITSCRIPT_PACKAGES = "${PN}"
INITSCRIPT_PARAMS = "start"
INITSCRIPT_NAME = "heartbeat.sh"
do_install_append()
{
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/heartbeat.sh ${D}${sysconfdir}/init.d/heartbeat.sh
install -d ${D}/home/root
install -m 0755 ${WORKDIR}/heartbeat ${D}/home/root/heartbeat
}
FILES_${PN} += "${sysconfdir}/init.d/heartbeat.sh /home/root/heartbeat"
PACKAGES = "${PN}"
I'm able to create the sdcard image succesfully with the patch I've included in this bbappend file, however, the files heartbeat.sh and heartbeat are not copying to the final rootfs added to the output sdcard file. This is very odd because I'm able to see these files in their paths copied to ../tmp/work/imx6sxsabresd-poky-linux-gnueabi/linux-imx/4.14.98-r0/image/
As the comments suggests appending to the kernel recipe is the wrong way to go about this. You should instead add your own recipe and reference that recipe from the image definition (append to IMAGE_INSTALL).
Your recipe could look something like:
SUMMARY = "LED heartbeat init script"
inherit update-rc.d
SRC_URI += "\
file://heartbeat.sh \
"
do_install() {
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/heartbeat.sh ${D}${sysconfdir}/init.d/
}
FILES_${PN} = "${sysconfdir}/init.d/heartbeat.sh"
INITSCRIPT_NAME = "heartbeat.sh"
INITSCRIPT_PARAMS = "start 90 5 . stop 20 0 1 6 ."

Yocto build not including files in sdcard image

I am trying to build an SDK into my sysroot on my yocto build. However when i compile my build i get no errors and everything appears to have worked fine.
When i flash my SD card and run it on my board and go to look for my files, they arent there.
here is my .bb file which is used to install the SDK i want to use.
giffgaff-connectDESCRIPTION = "azure"
HOMEPAGE = "https://github.com/Azure/azure-iot-sdk-c"
LICENSE = "MIT"
SECTION = "applications"
PRIORITY = "optional"
DEPENDS = "mono"
LIC_FILES_CHKSUM = "file://${WORKDIR}/git/LICENSE;md5=4283671594edec4c13aeb073c219237a"
SRCREV = "${AUTOREV}"
SRC_URI = "git://git#bitbucket.org/condecosoftware/azure-iot-sdk-c;protocol=ssh;branch=master"
COMPATIBLE_MACHINE = "imx6qsabresd"
S = "${WORKDIR}"
ALLOW_EMPTY_${PN} = "1"
do_compile() {
echo libdir: ${libdir}
echo Files : FILES_${PN}
echo "compiler: ${CC}"
echo "sysroot: ${STAGING_DIR_TARGET}"
export SYSROOT=${STAGING_DIR_TARGET}
cd ${WORKDIR}/git/build_all/linux/
./build.sh --toolchain-file toolchain-yocto.cmake -cl --sysroot=${STAGING_DIR_TARGET} --install-path-prefix ${STAGING_DIR_TARGET}
cd ../..
cmake -P cmake/iotsdk_linux/cmake_install.cmake
}
do_install() {
cd git
pwd
echo ${D}
echo ${libdir}
install -d 0755 ${D}${libdir}
install -m 0755 ./cmake/iotsdk_linux/umqtt/libumqtt.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/uamqp/libuamqp.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/c-utility/libaziotsharedutil.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client_http_transport.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client_amqp_ws_transport.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client_amqp_transport.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client_mqtt_transport.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_client/libiothub_client_mqtt_ws_transport.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/serializer/libserializer.a ${D}${libdir}/
install -m 0755 ./cmake/iotsdk_linux/iothub_service_client/libiothub_service_client.a ${D}${libdir}/
}
do_fetch_extra(){
cd ${WORKDIR}/git/
git submodule update --init --recursive
}
addtask fetch_extra after do_unpack before do_patch
Any help would be great appreciated. Thanks
Have you tried ${WORKDIR} variable? This variable holds the pathname of the work directory of recipe being build. So every file fetched from git can be accessed from there, I presume. For example:
install -m 0755 ${WORKDIR}/cmake/iotsdk_linux/umqtt/libumqtt.a ${D}${libdir}/
Please let me know if it works.
You will probably need to add
PACKAGES =+ "${PN}-staticdev"
FILES_${PN}-staticdev += "${libdir}/*.a"
to ship every files you installed into your image.
You can also add every files one by one instead of wildcard.
Some remarks:
For git submodules, you can use gitsm:// url, it will initialize every submodules.
You can also put the following instruction to avoid doing some change dir in recipe.
S = "${WORKDIR}/git"
By the way, you can look this OE recipe for Azure from Intel meta-iot-cloud layer. It is python recipe, but it depends on C iot sdk, it can be inspiring:
https://github.com/intel-iot-devkit/meta-iot-cloud/blob/master/recipes-azure/azure-iot-sdk/azure-iot-sdk_1.1.23.bb

Bitbake does not install my files in my rootfs

My aim is to create Bitbake recipe, that will install config file in /etc directory, and script, that will apply this config into /ect/init.d directory (and invoke update-rc-d).
I already saw another similar question (Bitbake not installing my file in the rootfs image). I did almost exactly what this guy did, but unfortunately it didn't work.
The problem is that Bitbake does not complain on anything, but just not adds these files to rootfs.
Here is my current recipe. I also put my script and config files to two directories: files, and alsa-config, which resides inside recipe directory.
SUMMARY = "Alsa Config"
DESCRIPTION = "Adds alsa configuration file, and startup script that applies it."
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI += " \
file://my-alsa-config \
file://asound.state \
"
PACKAGE_ARCH = "${MACHINE_ARCH}"
S = "${WORKDIR}"
INITSCRIPT_NAME = "my-alsa-config"
INITSCRIPT_PARAMS = "defaults 99 01"
inherit autotools update-rc.d
do_install() {
install -m 0644 ${WORKDIR}/asound.state ${D}${sysconfdir}
}
FILES_${PN} += "${sysconfdir}/asound.state"
In my local.conf I added line:
CORE_IMAGE_EXTRA_INSTALL += "alsa-config "
Please, can anybody help?
Fortunately, I was able to solve the problem. Here is the solution:
SUMMARY = "Alsa Config"
DESCRIPTION = "Adds alsa configuration file, and startup script that applies it."
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI += " \
file://my-alsa-config \
file://asound.state \
"
PACKAGE_ARCH = "${MACHINE_ARCH}"
S = "${WORKDIR}"
INITSCRIPT_NAME = "my-alsa-config"
INITSCRIPT_PARAMS = "defaults 99 01"
inherit autotools update-rc.d
do_install() {
install -d ${D}${sysconfdir}/init.d/
install -m 0755 ${WORKDIR}/my-alsa-config ${D}${sysconfdir}/init.d/
install -m 0644 ${WORKDIR}/asound.state ${D}${sysconfdir}/
}
FILES_${PN} += "${sysconfdir}/asound.state \
${sysconfdir}/my-alsa-config"
A little bit of comments:
PACKAGE_ARCH has to be set properly. In my case, when I didn't have it, execute permissions for script file were not set for some reason.
do_install() has to create every directory, that is needed. Even if I know, that in my rootfs there will be /etc directory, I have to create it. And I'm not sure if it is necessary, but it's better to have slash at the end of install directory, just in case.
Init scripts that are to be installed to launch at startup has to be installed too;)
Scripts must have proper permissions set.