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