Search code examples
linuxyoctobitbake

Yocto Service Not Starting


It took me a long time to get here. I have a custom application saved in GitLab and building in my VM. I am trying to add my application to my Linux build and start it as a service. My issue is the service is not starting and I cannot find my code on the target device.

In my applicaiton.bb I have the following line, I can confirm the application is being built when I use bitbake.

IMAGE_INSTALL_append = " helloworld "

My folder layout for the custom layer application is as follows.

enter image description here

I have updated my application bb file to include the service folder and files. The service file is very basic.

 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 \
            "
    
    S = "${WORKDIR}/src"
    
    inherit systemd
    SYSTEMD_AUTO_ENABLE = "enable"
    SYSTEMD_SERVICE_${PN} = "helloworld.service"
    
    SRC_URI_append = " file://helloworld.service "
    FILES_${PN} += "${systemd_unitdir}/system/helloworld.service"
    
    do_install_append() {
      install -d ${D}/${systemd_unitdir}/system
      install -D -m 0644 ${WORKDIR}/helloworld.service ${D}${systemd_unitdir}/system
  sed -i -e 's,@BINDIR@,${bindir},g' ${D}${systemd_unitdir}/helloworld.service
    }

Service File

[Unit]
Description=Example service

[Service]
Type=forking
ExecStart=@BINDIR@/helloworld

[Install]
WantedBy=multi-user.target

I have searched GitHub for examples of bb files that have SYSTEMD_AUTO_ENABLE and a service added. They are doing nothing special and I am confused as to why my service does not start, or appear on my device.

Update: The code is on the device but was installed in /lib/systemd/system/helloworld.service

The service file is looking for it in ExecStart=/usr/bin/helloworld This looks like an easy fix and I will update!

Update 2: I added the SED command which is supposed to copy the file from the systemd folder to the bin folder. I have yet to get this command working correctly.


Solution

  • I finally found the answer!

    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://helloworld.service \
        file://helloworld.c \
        "
    
    S = "${WORKDIR}"
    
    inherit systemd
    SYSTEMD_AUTO_ENABLE = "enable"
    SYSTEMD_SERVICE_${PN} = "helloworld.service"
    
    do_compile () {
        ${CC} ${LDFLAGS} helloworld.c -o helloworld
    }
    
    do_install_append() {
      install -d ${D}${bindir}
      install -m 0755 ${WORKDIR}/helloworld ${D}${bindir}
    
      install -d ${D}${systemd_unitdir}/system
      install -m 0644 ${WORKDIR}/helloworld.service ${D}${systemd_unitdir}/system
      sed -i -e 's,@BINDIR@,${bindir},g' ${D}${systemd_unitdir}/system/helloworld.service
    }