Reputation: 723
I am trying to enable a systemd service automatically after successful boot of my STM32MP1 based Avnger96 board. I am using Yocto Project as build system with Ubuntu 20.04. My image recipe to enable systemd service is example-systemd.bb
:
.
.
inherit systemd
SRC_URI = "file://example.sh \
file://example.service \
"
S = "${WORKDIR}"
SYSTEMD_AUTO_ENABLE_${PN} = "enable"
SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE_${PN} = "example.service"
do_install_append() {
install -d 644 ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/example.sh ${D}${sysconfdir}/init.d
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/example.service ${D}${systemd_system_unitdir}
}
FILES_${PN} += "${sysconfdir}/init.d"
FILES_${PN} += "${systemd_system_unitdir}/example.service"
REQUIRED_DISTRO_FEATURES= " systemd"
And included in my main image in local.conf
with IMAGE_INSTALL_append = " example-systemd"
After building the image, bitbake -e (YOUR_IMAGE) | grep ^DISTRO_FEATURES=
shows systemd
.
But in my rootfs I can't find systemd/system
directory with above service file. And also when I run systemctl status example
I get the error -sh: systemctl: command not found
.
Update
After including DISTRO_FEATURES_append= " systemd"
in the example-service.bb
, in the rootfs etc/systemd/system/multi-user.target.wants/
is created and it contains example.service file. But doing cat example.service
results in cat: example.service: No such file or directory
. Is this expected?
Can anyone please let me know how to run this service with systemd and how to check if service is installed and executed from linux user space?
And also I have one more doubt: Can both Systemd and Sysvinit exist together and some services are run by systemd and others by sysvinit?
Your help will be much appreciated.
Thanks in advance.
P.S: Please let me know if any info is missing here
Upvotes: 4
Views: 13660
Reputation: 194
If you are using Yocto Kirkstone or later, be sure to change the line
SYSTEMD_SERVICE_${PN} = "example.service"
To
SYSTEMD_SERVICE:${PN} = "example.service"
I ran into this issue when upgrading from Hardknott to Kirkstone. Yocto built and installed just fine, but none of my custom services were starting on boot. I was missing that :
and it didn't throw an error on build.
Upvotes: 2
Reputation: 1273
Your project might still use systemv
or something else as init manager instead of systemd
.
You can enable systemd
by adding these lines to your local.conf
(for versions Kirkstone and newer):
DISTRO_FEATURES:append = " systemd usrmerge"
DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit"
VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = "systemd-compat-units"
You can enable systemd
by adding these lines to your local.conf
(for versions Honister and older):
DISTRO_FEATURES_append = " systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit"
VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = "systemd-compat-units"
Upvotes: 4