Changes between Initial Version and Version 1 of Yocto/services


Ignore:
Timestamp:
10/22/2017 05:28:45 AM (6 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Yocto/services

    v1 v1  
     1[[PageOutline]]
     2
     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.
     5
     6Services exist in /etc/init.d:
     7{{{
     8root@ventana:~# ls /etc/init.d
     9alignment.sh              hostapd                   rmnologin.sh
     10alsa-state                hostname.sh               rpcbind
     11apmd                      hwclock.sh                run-postinsts
     12avahi-daemon              modutils.sh               save-rtc.sh
     13banner.sh                 mountall.sh               sendsigs
     14bootlogd                  mountnfs.sh               single
     15bootmisc.sh               neard                     stop-bootlogd
     16checkroot.sh              networking                sysfs.sh
     17dbus-1                    ofono                     syslog
     18devpts.sh                 populate-volatile.sh      syslog.busybox
     19dmesg.sh                  psplash.sh                udev
     20dnsmasq                   rc                        udev-cache
     21dropbear                  rc.local                  umountfs
     22functions                 rcS                       umountnfs.sh
     23functions.initscripts     read-only-rootfs-hook.sh  urandom
     24halt                      reboot
     25}}}
     26
     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:
     28{{{
     29id:5:initdefault:
     30}}}
     31
     32Symbolic links for runlevel 5 exist in /etc/rc.
     33The update-rc.d application is used to configure services:
     34{{{
     35root@ventana:~# ls /etc/rc5.d/
     36S01networking     S15mountnfs.sh    S20hwclock.sh     S64neard
     37S02dbus-1         S20apmd           S20syslog         S99rc.local
     38S10dropbear       S20dnsmasq        S21avahi-daemon   S99rmnologin.sh
     39S12rpcbind        S20hostapd        S22ofono          S99stop-bootlogd
     40}}}
     41
     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.
     43
     44To remove (disable) a service that is installed aside from removing the package you could disable it with the update-rc.d command:
     45{{{
     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
     56}}}
     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
     58
     59To enable a service to start with priority 10 for runlevel 5 you could use the following:
     60{{{
     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.
     65}}}
     66
     67To see the init configuration for a particular service, you can use ls to inspect symlinks:
     68{{{
     69root@ventana:~# ls /etc/rc*.d/*hostapd*
     70/etc/rc5.d/S10hostapd
     71}}}
     72 * The above shows how we have modified hostapd to start in runlevel 5 only
     73
     74To get see what services will start before and after each other, look at an alphabetic listing of a particular runlevel:
     75{{{
     76root@ventana:~# ls /etc/rc5.d/
     77S01networking     S12rpcbind        S20hwclock.sh     S64neard
     78S02dbus-1         S15mountnfs.sh    S20syslog         S99rc.local
     79S10dropbear       S20apmd           S21avahi-daemon   S99rmnologin.sh
     80S10hostapd        S20dnsmasq        S22ofono          S99stop-bootlogd
     81}}}
     82 * here you can see the networking starts first (01), then dbus-1 (02) then dropbear etc
     83
     84See also:
     85 * [http://unixhelp.ed.ac.uk/CGI/man-cgi?init+8 sysvinit man page]
     86 * [http://manpages.ubuntu.com/manpages/hardy/man8/update-rc.d.8.html update-rc.d man page]
     87 * [wiki:Yocto/packages add and remove Yocto packages]
     88
     89= Configuring packages to start/stop services at build time =
     90You can specify how your Yocto packages interact with '''sysvinit''' at build time.
     91
     92For more info:
     93 * [http://www.yoctoproject.org/docs/1.6.1/dev-manual/dev-manual.html#new-recipe-enabling-system-services Yocto documentation]
     94