Changes between Initial Version and Version 1 of Yocto/services

10/22/2017 05:28:45 AM (5 years ago)



  • Yocto/services

    v1 v1  
     3= Adding and Removing services for Yocto at runtime =
     4Yocto 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.
     6Services exist in /etc/init.d:
     8root@ventana:~# ls /etc/init.d              hostapd         
     10alsa-state                     rpcbind
     11apmd                            run-postinsts
     12avahi-daemon                               sendsigs
     14bootlogd                       single               neard                     stop-bootlogd              networking      
     17dbus-1                    ofono                     syslog             syslog.busybox                        udev
     20dnsmasq                   rc                        udev-cache
     21dropbear                  rc.local                  umountfs
     22functions                 rcS             
     23functions.initscripts  urandom
     24halt                      reboot
     27The '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:
     32Symbolic links for runlevel 5 exist in /etc/rc.
     33The update-rc.d application is used to configure services:
     35root@ventana:~# ls /etc/rc5.d/
     36S01networking     S64neard
     37S02dbus-1         S20apmd           S20syslog         S99rc.local
     38S10dropbear       S20dnsmasq        S21avahi-daemon
     39S12rpcbind        S20hostapd        S22ofono          S99stop-bootlogd
     42Enabling 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.
     44To remove (disable) a service that is installed aside from removing the package you could disable it with the update-rc.d command:
     46root@ventana:~# update-rc.d -f hostapd remove
     47update-rc.d: /etc/init.d/hostapd exists during rc.d purge (continuing)
     48 Removing any system startup links for hostapd ...
     49  /etc/rc0.d/K20hostapd
     50  /etc/rc1.d/K20hostapd
     51  /etc/rc2.d/S20hostapd
     52  /etc/rc3.d/S20hostapd
     53  /etc/rc4.d/S20hostapd
     54  /etc/rc5.d/S20hostapd
     55  /etc/rc6.d/K20hostapd
     57 * 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
     59To enable a service to start with priority 10 for runlevel 5 you could use the following:
     61root@ventana:~# update-rc.d hostapd start 10 5
     62action with list of runlevels not terminated by `.'
     63root@ventana:~# update-rc.d hostapd start 10 5 .
     64 Adding system startup for /etc/init.d/hostapd.
     67To see the init configuration for a particular service, you can use ls to inspect symlinks:
     69root@ventana:~# ls /etc/rc*.d/*hostapd*
     72 * The above shows how we have modified hostapd to start in runlevel 5 only
     74To get see what services will start before and after each other, look at an alphabetic listing of a particular runlevel:
     76root@ventana:~# ls /etc/rc5.d/
     77S01networking     S12rpcbind     S64neard
     78S02dbus-1    S20syslog         S99rc.local
     79S10dropbear       S20apmd           S21avahi-daemon
     80S10hostapd        S20dnsmasq        S22ofono          S99stop-bootlogd
     82 * here you can see the networking starts first (01), then dbus-1 (02) then dropbear etc
     84See also:
     85 * [ sysvinit man page]
     86 * [ update-rc.d man page]
     87 * [wiki:Yocto/packages add and remove Yocto packages]
     89= Configuring packages to start/stop services at build time =
     90You can specify how your Yocto packages interact with '''sysvinit''' at build time.
     92For more info:
     93 * [ Yocto documentation]