[yocto] trouble getting systemd oneshot to run

Jeremy Thien jeremyt at adtecinc.com
Thu Mar 15 06:44:17 PDT 2018


Agreed. I would expect the service file to be in
/lib/systemd/system/canstart.service and a symbolic link in
/etc/systemd/system/network.target.wants/canstart.service.

If those are both present, then the problem is in the service file. If the
symbolic link is missing, try "systemctl enable canstart.service" to see if
there is any useful information. "systemctl start canstart.service" and
"systemctl status canstart.service" may also help.

In my particular service file, I wanted to start after networking is up so
I followed this post
<https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/>. In the
Install section, I have "WantedBy=multi-user.target". In the Unit section,
I have "After=network-online.target" and "Wants=network-online.target".

On Wed, Mar 14, 2018 at 10:28 PM Khem Raj <raj.khem at gmail.com> wrote:

> On Wed, Mar 14, 2018 at 3:20 PM Greg Wilson-Lindberg <GWilson at sakuraus.com>
> wrote:
>
>> I changed it to look like:
>>
>> PACKAGES += "${PN}-service"
>>
>> FILES_${PN} = "${datadir}/*"
>> FILES_${PN}-service = "${systemd_system_unitdir}/canstart.service"
>>
>> do_install () {
>>     if test -e ${WORKDIR}/can_start.sh &&
>>        test -e ${WORKDIR}/canstart.service; then
>>         install -d ${D}${datadir}/canstart
>>         install -m 0755 ${WORKDIR}/can_start.sh ${D}${datadir}/canstart
>>         install -d ${D}${systemd_system_unitdir}
>>         install -m 0644 ${WORKDIR}/canstart.service ${D}${systemd_system_unitdir}
>>         sed -i -e 's|@SCRIPTDIR@|${datadir}/canstart|g' ${D}${systemd_system_unitdir}/canstart.service
>>     fi}
>>
>> SYSTEMD_PACKAGES = "${PN}-service"
>> SYSTEMD_SERVICE_${PN}-service = "canstart.service"
>> SYSTEMD_AUTO_ENABLE_${PN}-service = "enable"
>>
>> Still got the same results, my task is not running at startup.
>> To make sure that there wasn't some problem in running the script, I
>> changed the ExecStart to echo to a file in /tmp. Nothing there. The
>> .service file is not being executed.
>> I've obviously got something totally messed up, but I'm darned if I
>> understand what it is.
>>
>>
> You can check with systemctl status and other commands on the service on
> running system and might find more details
>
>>
>> ------------------------------
>> *From:* Jeremy Thien <jeremyt at adtecinc.com>
>> *Sent:* Wednesday, March 14, 2018 1:08 PM
>> *To:* Greg Wilson-Lindberg
>> *Cc:* yocto at yoctoproject.org
>> *Subject:* Re: [yocto] trouble getting systemd oneshot to run
>>
>> I am no expert, but I have a similar recipe. It might be over
>> complicated, but I put the script in one package and the service in another
>> something like:
>>
>> PACKAGES += "${PN}-service"
>> FILES_${PN} = "${datadir}/canstart/canstart.sh "
>> FILES_${PN}-service = "${systemd_unitdir}/system/canstart.service "
>> SYSTEMD_PACKAGES = ${PN}-service"
>> SYSTEMD_SERVICE_${PN}-service = canstart.service"
>> SYSTEMD_AUTO_ENABLE_${PN}-service = "enable"
>>
>> Of course, this requires image to install both canstart and
>> canstart-service.
>>
>> Hope this helps,
>> Jeremy Thien
>>
>> On Wed, Mar 14, 2018 at 3:21 PM Greg Wilson-Lindberg <
>> GWilson at sakuraus.com> wrote:
>>
>>> I'm building yocto for a raspberry pi3 from Qt's b2qt version.
>>>
>>>
>>> I'm running into two problems, I've got all of the files copying to the
>>> correct locations but the .service is not running at startup. I used
>>> connman-conf.bb as the template for my .bb file:
>>>
>>>
>>> SUMMARY="recipe to create CAN bus startup service"
>>>
>>> LICENSE = "CLOSED"
>>> LIC_FILES_CHKSUM = ""
>>>
>>> inherit systemd
>>>
>>> SRC_URI = "file://can_start.sh \           file://canstart.service \"
>>>
>>> S = "${WORKDIR}"
>>>
>>> PACKAGE_ARCH = "${MACHINE_ARCH}"
>>>
>>> FILES_${PN} = "${datadir}/*"
>>> do_install () {
>>>     if test -e ${WORKDIR}/can_start.sh &&
>>>        test -e ${WORKDIR}/canstart.service; then
>>>         install -d ${D}${datadir}/canstart
>>>         install -m 0755 ${WORKDIR}/can_start.sh ${D}${datadir}/canstart
>>>         install -d ${D}${systemd_system_unitdir}
>>>         install -m 0644 ${WORKDIR}/canstart.service ${D}${systemd_system_unitdir}
>>>         sed -i -e 's|@SCRIPTDIR@|${datadir}/canstart|g' ${D}${systemd_system_unitdir}/canstart.service
>>>     fi}
>>>
>>> SYSTEMD_SERVICE_${PN} = "canstart.service"
>>>
>>>
>>> Service file:
>>>
>>> [Unit]
>>> Description=Startup CAN bus interface
>>>
>>> [Service]
>>> Type=oneshot
>>> ExecStart=@SCRIPTDIR@/can_start.sh
>>>
>>> [Install]
>>> WantedBy=network.target
>>>
>>>
>>> From looking at the connman-conf sample I'm setting everything up
>>> correctly and the service should default to running on startup but it is
>>> not.
>>>
>>> The second 'problem' is really just perplexing, if I dump the variables
>>> S contains a path to a directory in my root not "${WORKDIR}".
>>>
>>> Any and all help with this would be greatly appreciated.
>>>
>>>
>>> Regards,
>>>
>>> Greg Wilson-Lindberg
>>> --
>>> _______________________________________________
>>> yocto mailing list
>>> yocto at yoctoproject.org
>>> https://lists.yoctoproject.org/listinfo/yocto
>>>
>> --
>> Jeremy Thien
>> Director of Engineering | Adtec Digital
>> jeremy.thien at adtecdigital.net | mobile: +1 (904) 910-1749
>> <(904)%20910-1749>
>> --
>> _______________________________________________
>> yocto mailing list
>> yocto at yoctoproject.org
>> https://lists.yoctoproject.org/listinfo/yocto
>>
> --
Jeremy Thien
Director of Engineering | Adtec Digital
jeremy.thien at adtecdigital.net | mobile: +1 (904) 910-1749
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.yoctoproject.org/pipermail/yocto/attachments/20180315/bd8c386d/attachment.html>


More information about the yocto mailing list