OpenRC: Difference between revisions

From Alpine Linux
(Created page with '= Alpine Linux Init System = Alpine has the following tools for configuring a service to start at boot: * rc_add * rc_delete * rc_status Note that if your system doesn't provide...')
 
 
(30 intermediate revisions by 17 users not shown)
Line 1: Line 1:
= Alpine Linux Init System =
== Quick-Start Information ==
Alpine has the following tools for configuring a service to start at boot:
Alpine Linux uses [https://github.com/OpenRC/openrc OpenRC] for its init system.
* rc_add
* rc_delete
* rc_status


Note that if your system doesn't provide the rc_add, rc_delete, or rc_status utilities, try the following analogous commands:
The following commands are available to manage the init system:
* rc-update add <service name> <runlevel>
* Basics:
* rc-update del <service name> <runlevel>
{{Cmd|rc-update add <service> <runlevel>}}
* rc-status
{{Cmd|rc-update del <service> <runlevel>}}
{{Cmd|rc-service <service> <start stop restart> # ⇔ /etc/init.d/service <start stop restart>}}


== Adding a service to start at next boot ==
* To check services and their set runlevels:
usage: rc_add [-hv] [-s number] script
  {{Cmd|rc-status}}
  -h  Show help and exit.
  -k  Also add a corresponding kill link for shutdown/reboot.
  -s  Set two-digit start number (00-99). Default is 50.
  -S Add service as a system init service (rcS.d).
  -v  Turn on verbose output.


== Removing a service from starting at next boot ==
* To change to a different runlevel:
usage: rc_delete [-hv] [-l level] script...
  {{Cmd|openrc <runlevel>}}
  -h  Show help and exit.
  -l  Only remove from specified level. Default is all levels.
  -v Turn on verbose output.


== Show status on what services will start at next boot ==
* Reboot/Halt/Poweroff: (And their equivalent from traditional GNU/Linux systems)
  usage: rc_status [-hv] [-l level] [script]
{{Cmd|reboot  # ⇔ shutdown now -r}}
  -h Show help and exit.
{{Cmd|halt    # ⇔ shutdown now -H}}
  -l  Show only specified level.
{{Cmd|poweroff # ⇔ shutdown now -P}}
  -v Turn on verbose output.
 
== Available Runlevels ==
The available runlevels are:
* '''default''' - Used if no runlevel is specified. (This is generally the runlevel you want to add services to.)
* '''hotplugged'''
* '''manual'''
 
The special runlevels are:
* '''sysinit''' - Brings up system specific stuff such as <code>/dev</code>, <code>/proc</code> and optionally <code>/sys</code> for Linux based systems. It also mounts <code>/lib/rc/init.d</code> as a ramdisk using tmpfs where available unless <code>/</code> is mounted rw at boot. <code>'''rc'''</code> uses <code>/lib/rc/init.d</code> to hold state information about the services it runs. sysinit always runs when the host first starts and should not be run again.
* '''boot''' - Generally the only services you should add to the boot runlevel are those which deal with the mounting of filesystems, set the initial state of attached peripherals and logging. Hotplugged services are added to the boot runlevel by the system. All services in the boot and sysinit runlevels are automatically included in all other runlevels except for those listed here.
* '''single''' - Stops all services except for those in the sysinit runlevel.
* '''reboot''' - Changes to the shutdown runlevel and then reboots the host.
* '''shutdown''' - Changes to the shutdown runlevel and then halts the host.
 
== rc-update usage ==
  Usage: rc-update [options] add service <runlevel>
        rc-update [options] del service <runlevel>
        rc-update [options] show
Options: [suChqv]
  -s, --stack                      Stack a runlevel instead of a service
  -u, --update                      Force an update of the dependency tree
  -h, --help                        Display this help output
  -C, --nocolor                    Disable color output
  -v, --verbose                    Run verbosely
  -q, --quiet                      Run quietly
 
== rc-status usage ==
Usage: rc-status [options] [runlevel1] [runlevel2] ...
Options: [aclrsuChqv]
  -a, --all                        Show services from all run levels
  -c, --crashed                    Show crashed services
  -l, --list                        Show list of run levels
  -r, --runlevel                    Show the name of the current runlevel
  -s, --servicelist                Show service list
  -u, --unused                      Show services not assigned to any runlevel
  -h, --help                        Display this help output
  -C, --nocolor                    Disable color output
  -v, --verbose                    Run verbosely
  -q, --quiet                      Run quietly
 
== rc-service usage ==
Usage: rc-service [options]
Options: [e:ilr:ChqVv]
  -e, --exists <arg>                tests if the service exists or not
  -i, --ifexists                    if the service exists then run the command
  -l, --list                        list all available services
  -r, --resolve <arg>              resolve the service name to an init script
  -h, --help                        Display this help output
  -C, --nocolor                    Disable color output
  -V, --version                    Display software version
  -v, --verbose                    Run verbosely
  -q, --quiet                      Run quietly
 
== rc usage ==
Usage: rc [options]
Options: [a:o:s:SChqVv]
  -a, --applet <arg>                runs the applet specified by the next argument
  -o, --override <arg>              override the next runlevel to change into
                                    when leaving single user or boot runlevels
  -s, --service <arg>              runs the service specified with the rest
                                    of the arguments
  -S, --sys                        output the RC system type, if any
  -h, --help                        Display this help output
  -C, --nocolor                    Disable color output
  -V, --version                    Display software version
  -v, --verbose                    Run verbosely
  -q, --quiet                      Run quietly
 
== Preventing slow services from delaying boot ==
 
Services that take a while to start will block the boot process until they complete. E.g.: <code>iwd</code> and <code>networking</code> might delay startup of an interactive system rather than start in the background.
 
This can be remedied using [https://ptrcnull.me/posts/openrc-async-services/ async services]. See [https://wiki.gentoo.org/wiki/OpenRC/Stacked%20runlevel stacked runlevels] for more details on this.
 
== cgroups v2 ==
 
Since {{pkg|openrc}} 0.51 cgroups v2, or "unified", is the default.
You can enable hybrid cgroups v1 & v2 by editing <code>/etc/rc.conf</code> and setting <code>rc_cgroup_mode="hybrid"</code>.
 
Then you should run
{{Cmd|rc-service cgroups start}}
to take effect
 
and
  {{Cmd|rc-update add cgroups}}
to auto mount the cgroup filesystem on boot
 
== See also ==
* [https://wiki.gentoo.org/wiki/OpenRC Gentoo Wiki]
* [https://wiki.archlinux.org/title/OpenRC ArchWiki]
* [https://wiki.postmarketos.org/wiki/OpenRC PostmarketOS Wiki]
 
[[Category:Booting]]

Latest revision as of 11:26, 12 December 2023

Quick-Start Information

Alpine Linux uses OpenRC for its init system.

The following commands are available to manage the init system:

  • Basics:

rc-update add <service> <runlevel>

rc-update del <service> <runlevel>

rc-service <service> <start stop restart> # ⇔ /etc/init.d/service <start stop restart>

  • To check services and their set runlevels:

rc-status

  • To change to a different runlevel:

openrc <runlevel>

  • Reboot/Halt/Poweroff: (And their equivalent from traditional GNU/Linux systems)

reboot # ⇔ shutdown now -r

halt # ⇔ shutdown now -H

poweroff # ⇔ shutdown now -P

Available Runlevels

The available runlevels are:

  • default - Used if no runlevel is specified. (This is generally the runlevel you want to add services to.)
  • hotplugged
  • manual

The special runlevels are:

  • sysinit - Brings up system specific stuff such as /dev, /proc and optionally /sys for Linux based systems. It also mounts /lib/rc/init.d as a ramdisk using tmpfs where available unless / is mounted rw at boot. rc uses /lib/rc/init.d to hold state information about the services it runs. sysinit always runs when the host first starts and should not be run again.
  • boot - Generally the only services you should add to the boot runlevel are those which deal with the mounting of filesystems, set the initial state of attached peripherals and logging. Hotplugged services are added to the boot runlevel by the system. All services in the boot and sysinit runlevels are automatically included in all other runlevels except for those listed here.
  • single - Stops all services except for those in the sysinit runlevel.
  • reboot - Changes to the shutdown runlevel and then reboots the host.
  • shutdown - Changes to the shutdown runlevel and then halts the host.

rc-update usage

Usage: rc-update [options] add service <runlevel>
       rc-update [options] del service <runlevel>
       rc-update [options] show

Options: [suChqv]
  -s, --stack                       Stack a runlevel instead of a service
  -u, --update                      Force an update of the dependency tree
  -h, --help                        Display this help output
  -C, --nocolor                     Disable color output
  -v, --verbose                     Run verbosely
  -q, --quiet                       Run quietly

rc-status usage

Usage: rc-status [options] [runlevel1] [runlevel2] ...

Options: [aclrsuChqv]
  -a, --all                         Show services from all run levels
  -c, --crashed                     Show crashed services
  -l, --list                        Show list of run levels
  -r, --runlevel                    Show the name of the current runlevel
  -s, --servicelist                 Show service list
  -u, --unused                      Show services not assigned to any runlevel
  -h, --help                        Display this help output
  -C, --nocolor                     Disable color output
  -v, --verbose                     Run verbosely
  -q, --quiet                       Run quietly

rc-service usage

Usage: rc-service [options]

Options: [e:ilr:ChqVv]
  -e, --exists <arg>                tests if the service exists or not
  -i, --ifexists                    if the service exists then run the command
  -l, --list                        list all available services
  -r, --resolve <arg>               resolve the service name to an init script
  -h, --help                        Display this help output
  -C, --nocolor                     Disable color output
  -V, --version                     Display software version
  -v, --verbose                     Run verbosely
  -q, --quiet                       Run quietly

rc usage

Usage: rc [options]

Options: [a:o:s:SChqVv]
  -a, --applet <arg>                runs the applet specified by the next argument
  -o, --override <arg>              override the next runlevel to change into
                                    when leaving single user or boot runlevels
  -s, --service <arg>               runs the service specified with the rest
                                    of the arguments
  -S, --sys                         output the RC system type, if any
  -h, --help                        Display this help output
  -C, --nocolor                     Disable color output
  -V, --version                     Display software version
  -v, --verbose                     Run verbosely
  -q, --quiet                       Run quietly

Preventing slow services from delaying boot

Services that take a while to start will block the boot process until they complete. E.g.: iwd and networking might delay startup of an interactive system rather than start in the background.

This can be remedied using async services. See stacked runlevels for more details on this.

cgroups v2

Since openrc 0.51 cgroups v2, or "unified", is the default. You can enable hybrid cgroups v1 & v2 by editing /etc/rc.conf and setting rc_cgroup_mode="hybrid".

Then you should run

rc-service cgroups start

to take effect

and

rc-update add cgroups

to auto mount the cgroup filesystem on boot

See also