FAQ_MA35D1_Run Applications Automatically after Booting by Yocto
Posted: 30 Nov 2022, 16:51
Run applications after system boot
Linux kernel built by Yocto use systemd initialization, so we need to add a system service to run the applications which you want to run
1. Create systemd service file named “run-before-login-prompt.service” and edit the content below
/home/root/demo.sh is the application you want to run after booting
2. Put the service file to target board /lib/systemd/system/run-before-login-prompt.service
3. Reboot the device and it will run after booting
4. You can also use Yocto recipe to add the service file to /lib/systemd/system/
5. Refer to FAQ_MA35D1_Add a New Recipe in Yocto
This recipe demo how to install a file to root filesystem and run after booting
Linux kernel built by Yocto use systemd initialization, so we need to add a system service to run the applications which you want to run
1. Create systemd service file named “run-before-login-prompt.service” and edit the content below
/home/root/demo.sh is the application you want to run after booting
Code: Select all
[Unit]
Description=Run script with systemd right before login prompt
[Service]
Type=idle
RemainAfterExit=yes
ExecStart=/home/root/demo.sh
StandardOutput=journal+console
[Install]
WantedBy=multi-user.target
3. Reboot the device and it will run after booting
4. You can also use Yocto recipe to add the service file to /lib/systemd/system/
5. Refer to FAQ_MA35D1_Add a New Recipe in Yocto
This recipe demo how to install a file to root filesystem and run after booting
Code: Select all
SUMMARY = "Demo how to install files to root filesystem and run after booting"
LICENSE = "CLOSED"
inherit systemd
SYSTEMD_AUTO_ENABLE = "enable"
SYSTEMD_SERVICE_${PN} = "run-before-login-prompt.service"
SRC_URI = "file://run-before-login-prompt.service \
file://demo.sh \
"
S = "${WORKDIR}"
do_install() {
install -d ${D}/${ROOT_HOME}
install -m 0777 ${S}/demo.sh ${D}${ROOT_HOME}/demo.sh
install -d ${D}/${systemd_unitdir}/system
install -m 0644 ${S}/run-before-login-prompt.service ${D}${systemd_unitdir}/system
}
FILES_${PN} = "${bindir} ${systemd_unitdir}/system/* ${ROOT_HOME}"