0

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
  • 1
    I have no idea how does this really relate to Go but let's try to guess. Care to include the output of running `systemctl status -l https-server` (that's a small Latin letter L; ell) in your question? – kostix Apr 30 '20 at 16:16
  • 1
    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. You can check with `oe-pkgdata-util list-pkg-files -p https-server` if files are correctly packaged. You can check with `bitbake -e https-server | egrep '^[A-Z][A-Z_]*'` if variables are set correctly. And also check @kostix command. There is also [SYSTEMD_AUTO_ENABLE](https://www.yoctoproject.org/docs/current/mega-manual/mega-manual.html#var-SYSTEMD_AUTO_ENABLE) variable you could check but it should be enabled by default. – Nayfe Apr 30 '20 at 17:14
  • @kostix [I have no idea how does this really relate to Go..] You are right, I removed the wrong tags, sorry for that. –  May 04 '20 at 05:29
  • [Care to include the output of running "systemctl status -l https-server" ] The command systemctl is not running on my target, I try to add it and will try. Thanks. –  May 04 '20 at 05:55

1 Answers1

0

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.