Service is not running at startup

Good morning,
We have a system that we are building on an Apalis imx8 board. We use a custom imagebase on the “tdx-reference-minimal-image” and we TFTP Boot the board with that image, which works perfectly. This image has a service that we created using a custom layer/custom recipe, this service has the followings:
→ A script Set the password for user “root” : “set_root_password.sh”
→ other files to Configure ssh with id_rsa.pub key to be able to remote login to the board.
→ A service to run on startup one time {After=getty.target}, this service is the entry point to start the set_root_password.
Note that set_root_password.sh set all other need configuration such as network configuration.
The problem is the service doesnt run on startup. It only works if i manually run it using: systemctl start custom-ssh-service.

Here is how the config.bb and the custom-ssh-service:
//-----------------------------------------------------------------------------------
config.bb:

SUMMARY = “Custom SSH Configuration”
DESCRIPTION = “Custom SSH Configuration for Apalis iMX8”

LICENSE = “MIT”

License checksum file is always required

LIC_FILES_CHKSUM = “file://${COREBASE}/meta/files/common-licenses/MIT;md5=

#inherit systemd

SRC_URI = “file://id_rsa.pub
file://sshd_config
file://sshd.socket
file://set_root_password.sh
file://set_authorized_keys.sh
file://custom-ssh-symlink.service
file://custom-ssh-service.service”

S = “${WORKDIR}”

inherit update-rc.d systemd

SYSTEMD_PACKAGES = “${PN}”
INITSCRIPT_PACKAGES = “${PN}”

SYSTEMD_AUTO_ENABLE ??= “enable”
SYSTEMD_SERVICE_${PN} = “custom-ssh-service.service”

do_install() {
install -d ${D}${sysconfdir}/ssh/
install -d ${D}${sysconfdir}/systemd/system/
install -d ${D}${bindir}

install -m 0644 ${WORKDIR}/id_rsa.pub ${D}${sysconfdir}/ssh/
install -m 0644 ${WORKDIR}/sshd_config ${D}${sysconfdir}/ssh/
install -m 0644 ${WORKDIR}/sshd.socket ${D}${sysconfdir}/systemd/system/
install -m 0755 ${WORKDIR}/set_root_password.sh ${D}${bindir}/
install -m 0755 ${WORKDIR}/set_authorized_keys.sh ${D}${bindir}/
install -m 0644 ${WORKDIR}/custom-ssh-symlink.service ${D}${sysconfdir}/systemd/system/
install -m 0644 ${WORKDIR}/custom-ssh-service.service ${D}${sysconfdir}/systemd/system/

}

FILES_${PN} += “${sysconfdir}/ssh/
${sysconfdir}/systemd/system/
${sysconfdir}/ssh/authorized_keys
${bindir}/set_authorized_keys.sh
${bindir}/set_root_password.sh
${sysconfdir}/systemd/system/custom-ssh-service.service
${sysconfdir}/systemd/system/custom-ssh-symlink.service
${bindir}/”

pkg_postinst:${PN}() {
mkdir -p $D${sysconfdir}/systemd/user/default.target.wants
ln -s ${sysconfdir}/systemd/system/custom-ssh-service.service $D${sysconfdir}/systemd/user/default.target.wants/custom-ssh-service.service
}

//--------------------------------------------------------------------------------------------------------------------------
custom-ssh-service:

[Unit]
Description=Custom SSH Configuration Service
#After=network.target
##--------------------------------------
After=multi-user.target
##-------------------------------------
#After=systemd-user-sessions.service

plymouth-quit-wait.service

#After=rc-local.service
Before=getty.target
IgnoreOnIsolate=yes
#----------------------------------------
#Documentation=man:systemd-firstboot(1)
#DefaultDependencies=no
#Conflicts=shutdown.target
#After=systemd-remount-fs.service
#Before=systemd-sysusers.service sysinit.target shutdown.target
#ConditionPathIsReadWrite=/etc
#---------------------------------------

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/set_root_password.sh start
ExecStart=/usr/bin/set_authorized_keys.sh start

[Install]
WantedBy=multi-user.target
#WantedBy=basic.target

//------------------------------------------------------------------------------------------------------------------------
Please, help us figure out why the service is not running on startup, Thanks!

@blouisb2,

When at the first boot (service not auto-started) , can you post the systemctl status <service_name> output? The service does need to be enabled in order to start on boot.

It may also be beneficial to break up your custom service into separate services, with appropriate before/after to isolate the problem area.

And also can you post/review the logs provided via journalctl -u <service_name>

-Eric

Good morning,
I now know that it is best to have one service per recipe. Though, that was not the solution. The solution was to add “do_install:append” before FILES_${PN} and remove pkg_postinst (See image).
Additionally, the board booted with no logs, adding IMAGE_INSTALL +="rsyslog"in the conf/local.conf is very helpful for debugging.
Side note, to find if a package is available when building the image this command help:
→ bitbake -s | grep rsyslog
I was able to know there is “rsyslog” Whereas there is no “plocate” in seconds.

Anyway, I appreciate the help.