|Version 1 (modified by 6 years ago) ( diff ),
Adding and Removing services for Yocto at runtime
Yocto uses a fairly standard Linux init system (called sysvinit) for system init for managing services. A service is a process that usually starts on boot and runs in the background.
Services exist in /etc/init.d:
root@ventana:~# ls /etc/init.d alignment.sh hostapd rmnologin.sh alsa-state hostname.sh rpcbind apmd hwclock.sh run-postinsts avahi-daemon modutils.sh save-rtc.sh banner.sh mountall.sh sendsigs bootlogd mountnfs.sh single bootmisc.sh neard stop-bootlogd checkroot.sh networking sysfs.sh dbus-1 ofono syslog devpts.sh populate-volatile.sh syslog.busybox dmesg.sh psplash.sh udev dnsmasq rc udev-cache dropbear rc.local umountfs functions rcS umountnfs.sh functions.initscripts read-only-rootfs-hook.sh urandom halt reboot
The 'init' process (PID 1) is launched from the kernel after the root filesystem has been mounted. It processes /etc/inittab which dictates what 'runlevel' to enter on boot and what init services to kick off. The various run levels each have their own directories containing symbolic links to the services in /etc/init.d. These links are prefixed with 'S' for startup, and 'K' for shutdown and a numeric that determines the order they are run in. For example, a default /etc/inittab contains the following line which tells the system to start in runlevel 5:
Symbolic links for runlevel 5 exist in /etc/rc. The update-rc.d application is used to configure services:
root@ventana:~# ls /etc/rc5.d/ S01networking S15mountnfs.sh S20hwclock.sh S64neard S02dbus-1 S20apmd S20syslog S99rc.local S10dropbear S20dnsmasq S21avahi-daemon S99rmnologin.sh S12rpcbind S20hostapd S22ofono S99stop-bootlogd
Enabling and disabling services becomes a task of creating and removing symbolic links to the various /etc/rc*.d/ directories. This can be done for you using the update-rc.d package. Some packages may define default priorities and run levels in their init script - others do not, or you may want to override them anyway.
To remove (disable) a service that is installed aside from removing the package you could disable it with the update-rc.d command:
root@ventana:~# update-rc.d -f hostapd remove update-rc.d: /etc/init.d/hostapd exists during rc.d purge (continuing) Removing any system startup links for hostapd ... /etc/rc0.d/K20hostapd /etc/rc1.d/K20hostapd /etc/rc2.d/S20hostapd /etc/rc3.d/S20hostapd /etc/rc4.d/S20hostapd /etc/rc5.d/S20hostapd /etc/rc6.d/K20hostapd
- Note the '-f' parameter above to force update-rc.d to do your bidding - this overrides any default behavior it may have if you try to do something that disagree's with the packages default configuration
To enable a service to start with priority 10 for runlevel 5 you could use the following:
root@ventana:~# update-rc.d hostapd start 10 5 action with list of runlevels not terminated by `.' root@ventana:~# update-rc.d hostapd start 10 5 . Adding system startup for /etc/init.d/hostapd.
To see the init configuration for a particular service, you can use ls to inspect symlinks:
root@ventana:~# ls /etc/rc*.d/*hostapd* /etc/rc5.d/S10hostapd
- The above shows how we have modified hostapd to start in runlevel 5 only
To get see what services will start before and after each other, look at an alphabetic listing of a particular runlevel:
root@ventana:~# ls /etc/rc5.d/ S01networking S12rpcbind S20hwclock.sh S64neard S02dbus-1 S15mountnfs.sh S20syslog S99rc.local S10dropbear S20apmd S21avahi-daemon S99rmnologin.sh S10hostapd S20dnsmasq S22ofono S99stop-bootlogd
- here you can see the networking starts first (01), then dbus-1 (02) then dropbear etc
Configuring packages to start/stop services at build time
You can specify how your Yocto packages interact with sysvinit at build time.
For more info: