22

Hi this is my layer tree

├── conf
│   └── layer.conf
├── COPYING.MIT
├── README
└── recipes-hello
    ├── helloworld
    │   ├── helloworld-0.1
    │   │   ├── helloworld.c
    │   │   ├── helloworld.patch
    │   │   └── newhelloworld.c
    │   └── helloworld_0.1.bb
    ├── message
    │   ├── message-0.1
    │   │   └── message.txt
    │   └── message_0.1.bb
    └── service
        ├── service-0.1
        │   ├── test_systemd.service
        │   └── test_systemd.sh
        └── service_0.1.bb

Here test_systemd.service is the service file which have to invoke test_systemd.sh, which I am trying to achieve using service_0.1.bb

    # This recipe performs the following tasks
    # 1) Install .sh file in /home/root/ and .sh script creates a random text file
    # 2) Install the .service file in systemd directory
    # 3) Invoke the .sh script via .service file
    inherit systemd

SUMMARY = "Install and start a systemd service"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

#here we specify the source we want to build
SRC_URI = "file://test_systemd.sh"
SRC_URI += "file://test_systemd.service"
#here we specify the source directory, where we can do all the building and expect sources to be placed
S = "${WORKDIR}"

SYSTEMD_SERVICE_${PN} = "test_systemd.service"


#bitbake task
#created a directory /home/root for target install the script
do_install() {
             install -d ${D}/home/root
             install -m 0755 ${WORKDIR}/test_systemd.sh ${D}/home/root

             install -d ${D}{systemd_system_unitdir}
             install -m 0644 ${WORKDIR}/test_systemd.service ${D}{systemd_system_unitdir}
}

#Pack the path
FILES_${PN} += "/home/root"
FILES_${PN} += "/lib/systemd/system"

REQUIRED_DISTRO_FEATURES= "systemd"

The problem is when I try to bitbake system recipe, bitbake throws an error saying test_systemd.service not found. I managed to install both the files in RFS with a previous attempt but when I include the systemd concept. I get the no such file error. What could be the reason ? Error message

 NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: service-0.1-r0 do_package: SYSTEMD_SERVICE_service value test_systemd.service does not exist
ERROR: service-0.1-r0 do_package: Function failed: systemd_populate_packages
ERROR: Logfile of failure stored in: /home/guest/yocto_practice/poky/build-beaglebone/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/service/0.1-r0/temp/log.do_package.2860
ERROR: Task (/home/guest/yocto_practice/meta-testlayer/recipes-hello/service/service_0.1.bb:do_package) failed with exit code '1'
NOTE: Tasks Summary: Attempted 514 tasks of which 506 didn't need to be rerun and 1 failed.

Summary: 1 task failed:
  /home/guest/yocto_practice/meta-testlayer/recipes-hello/service/service_0.1.bb:do_package
Summary: There were 2 ERROR messages shown, returning a non-zero exit code.

Also is this the correct way to write bb recipe for systemd and what is the significance of writing this

#Pack the path
    FILES_${PN} += "/home/root"
    FILES_${PN} += "/lib/systemd/system"

without this bitbake throws error.

0

2 Answers 2

27
SYSTEMD_SERVICE_${PN} += "file://test_systemd.service"

This should be:

SYSTEMD_SERVICE_${PN} = "test_systemd.service"

Other notes (unrelated to the error):

  • Installing things into /home is probably not a great idea (you could use e.g. ${libexecdir} for scripts that other scripts need.
  • there's no reason for having a do_install_append() in a bb file: you can just put everything in do_install()
  • If your Yocto is recent, using ${systemd_system_unitdir} instead of /lib/systemd/system is a good idea (in older releases ${systemd_unitdir}/system/ works)
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for suggesting for mods. I did changes according to you but still getting the error. Will update the question
I still get the same error. Don't know why bitbake couldn't find the file at the location where it exists.
Your current recipe refers twice to ${D}{systemd_system_unitdir}. It should be ${D}${systemd_system_unitdir}. Otherwise it works here.
Thanks for the other notes, I learned something new about systemd_system_unitdir!
1

In order to resolve this packaging error, I used the following install step

do_install() {
   install -d ${D}${bindir}
   install -m 0755 ${WORKDIR}/test_systemd.sh ${D}${bindir}
   install -d ${D}${systemd_unitdir}/system
   install -m 0644 ${WORKDIR}/test_systemd.service ${D}${systemd_unitdir}/system
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.