OpenRC
- Review for accuracy & test.
- Complete to cover most basic usage under Gentoo.
- Rework for precision, readability, concision...
- Section BusyBox Integration needs testing and documenting (or removing).
OpenRC は、通常 /sbin/init にありシステムが提供する init システムと互換性のある、Unix 系システムのための依存関係ベースの init システムです。Gentoo では他の init システムも利用できますが、OpenRC が Gentoo のネイティブの init システムです。
OpenRC は、ブート時に必要なサービスを正しい順序で開始し、システムの使用中はそれらを管理し、シャットダウン時にそれらを終了します。Gentoo リポジトリからインストールされたデーモンを管理でき、デーモンが起動するプロセスがある場合はそれらを監視でき、ブート時間を短縮するために可能であればプロセスを並列で開始することもできます。
OpenRC は Gentoo のために開発されましたが、他の Linux ディストリビューションと BSD システムでも使えるように設計されています。Gentoo 上ではデフォルトでは、OpenRC は sysvinit によって呼び出されます。
Gentoo リポジトリ以外からインストールされたデーモン (例えば、ソースコードとしてダウンロードして手動でコンパイルされたソフトウェア) は、OpenRC とともに機能するように適応させる必要があるかもしれません (些細な変更で済む場合もあります)。
OpenRC プロジェクト自身が提供するドキュメンテーションへのリンクは、OpenRC ドキュメンテーションの節を参照してください。 OpenRC が init システムとともにどう機能するかについての情報は、ハンドブックを参照してください。
実装
OpenRC は伝統的な Unix 系システムに、大きな、根本的な変更を必要としません。OpenRC は他のシステムソフトウェアを部品として、モジュール化された柔軟なシステムの一部となるようそれらと統合します。高速で、軽量で、簡単に設定でき、高い適応性を持つように設計されています。OpenRC の依存は少なく、コアシステムコンポーネントへの基本的な依存のみです。
現代的な init システムとして、OpenRC は便利な機能を多数提供しています:
- cgroups サポート。
- プロセス監視。
- サービスの並列開始にも対応した、依存関係ベースの起動。
- 依存関係の自動的解決と順序付け。
- ハードウェアによって開始される init スクリプト。
- rc_ulimit 変数を通じた、サービスごとの ulimit と nice 値の設定。
- 複数のコンポーネントを開始する複雑な init スクリプト。
- 既存のインフラストラクチャに適応する、モジュール化されたアーキテクチャ。
- OpenRC は openrc-init という選択可能な自身の init システムを持っています。詳細は OpenRC/openrc-init を参照してください。
- OpenRC は選択可能な自身のプロセス監視機能を持っています。詳細は OpenRC/supervise-daemon を参照してください。
init システムについてのさらなる情報は init システムの比較の記事を参照してください。
インストール
OpenRC は通常手動でインストールする必要はなく、インストール時に OpenRC プロファイルの一部として提供されます。stage 3 tarball 中に存在し、システム更新を通じて保守されるでしょう。
USE フラグ
USE flags for sys-apps/openrc OpenRC manages the services, startup and shutdown of a host
+netifrc
|
enable Gentoo's network stack (net.* scripts) |
+sysvinit
|
control the dependency on sysvinit (experimental) |
audit
|
Enable support for Linux audit subsystem using sys-process/audit |
bash
|
enable the use of bash in service scripts (experimental) |
debug
|
Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces |
newnet
|
enable the new network stack (experimental) |
pam
|
Add support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip |
s6
|
install s6-linux-init |
selinux
|
!!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur |
sysv-utils
|
Install sysvinit compatibility scripts for halt, init, poweroff, reboot and shutdown |
unicode
|
Add support for Unicode |
USE フラグが変更されたら、変更を反映するためにパッケージを再ビルドすることができます。OpenRC プロファイルでは、virtual/service-manager の依存として sys-apps/openrc が取り込まれるため、決して selected-packages 集合 (/var/lib/portage/world ファイル) に追加するべきではありません。--oneshot
オプションを使うと、この集合に OpenRC を追加せずにすみます。
root #
emerge --ask --oneshot sys-apps/openrc
設定
ファイル
- /etc/rc.conf
- グローバルな OpenRC 設定ファイル。
- OpenRC の設定について文書化した多数のコメントを含んでいます。
- /etc/conf.d
- 個別の init スクリプトのための設定ファイルを格納します。
ログ
OpenRC はデフォルトでは何もログを出力しません。ブート中の OpenRC の出力をログとして出力するには、/etc/rc.conf 内の rc_logger オプションのコメントアウトを解除して設定してください。ログはデフォルトでは /var/log/rc.log に保存されるでしょう。
/etc/rc.conf
rc_logger="YES"
#rc_log_path="/var/log/rc.log"
ネットワーク管理
OpenRC は、複数のネットワークマネージャのうちのいずれかとともに使用することができ、またどれとも組み合わせずに使用することもできます。デフォルトでは、Gentoo の OpenRC プロファイル では、netifrc スクリプトがネットワーク接続を管理するために利用されます。
ネットワーク管理に関する選択肢の一覧は、Network manager の記事を参照してください。
依存関係の振る舞い
より複雑なシステム構成に適応させるには、init スクリプトのデフォルトの依存関係を変更する必要があるかもしれません。デフォルトの振る舞いを変更する方法については /etc/rc.conf を参照してください; rc_depend_strict オプションに注意してください。さらに、次のネットワーク構成の例で OpenRC がどれほど柔軟になれるのかを示します。
- 複数のネットワークインターフェース (例)
SSH サービス は内部ネットワーク、例えば eth0 とともに開始しなくてはならず、wlan0 とともに開始してはならないとします。
/etc/init.d/sshd による "net" 依存を取り消して、"net.eth0" に依存するように改良します:
/etc/conf.d/sshd
rc_need="!net net.eth0"
- 複数のランレベル内での複数のネットワークインターフェース (例)
SSH サービスを、"default" ランレベルでは (wlan0 ではなく) eth0 とともに開始する必要があるが、"office" ランレベルでは (eth0 ではなく) wlan0 とともに開始する必要があるとします。
これはデフォルトのままにしてください:
/etc/rc.conf
#rc_depend_strict="YES"
sshd へのシンボリックリンクを、ネットワークインターフェースの名前付きで追加で作成してください:
root #
ln -s sshd /etc/init.d/sshd.eth0
root #
ln -s sshd /etc/init.d/sshd.wlan0
これで、/etc/conf.d/sshd.eth0 と /etc/conf.d/sshd.wlan0 から設定が読み込まれるようになりました:
root #
cp /etc/conf.d/sshd /etc/conf.d/sshd.eth0
root #
cp /etc/conf.d/sshd /etc/conf.d/sshd.wlan0
依存を追加してください:
root #
echo 'rc_need="!net net.eth0"' >> /etc/conf.d/sshd.eth0
root #
echo 'rc_need="!net net.wlan0"' >> /etc/conf.d/sshd.wlan0
この例では、net.eth0 と net.wlan0 はアクティブなランレベルに応じて、自身の設定を /etc/conf.d/net または /etc/conf.d/net.office から読み込みます。すべての runscript をそれぞれのランレベルに追加してください:
root #
rc-update add sshd.eth0 default
root #
rc-update add sshd.wlan0 office
root #
rc-update add net.eth0 default office
root #
rc-update add net.wlan0 default office
コンピュータを再起動せずに "default" ランレベルと "office" ランレベルの間で切り換えるには、間に "nonetwork" ランレベルを挟んで変更してください。こうすることでネットワークインターフェースが一度停止し、その後ランレベル固有の設定を再読み込みするでしょう。この方法は "nonetwork" がスタックされたランレベルとして "default" と "office" の両方に含まれるようにし、"nonetwork" ランレベルにのみディスプレイマネージャなどのネットワークを必要としないサービスを追加するようにすると、最も効果的に機能します。
default ランレベル <---> nonetwork ランレベル <---> office ランレベル
root #
openrc nonetwork && openrc office
root #
openrc nonetwork && openrc default
ブート時に特定のランレベルを選択する
OpenRC はブート時に使われるカーネルコマンドラインを読み、softlevel パラメータが提供されていれば、そこで指定されたランレベルを開始します。softlevel パラメータが提供されていない場合は、default ランレベルが使用されます。
次の例では、default または nonetwork のどちらのランレベルにブートするかを選べる grub 設定を示しています:
/boot/grub/grub.conf
grub.conf の例 (GRUB レガシー)title=Regular Start-up
kernel (hd0,0)/boot/kernel-3.7.10-gentoo-r1 root=/dev/sda3
title=Start without Networking
kernel (hd0,0)/boot/kernel-3.7.10-gentoo-r1 root=/dev/sda3 softlevel=nonetwork
追加のランレベルを追加する方法の説明については、以下の節をお読みください。
使い方
ランレベル
OpenRC は openrc、rc-update、そして rc-status コマンドを利用して制御と設定を行うことができます。
default ランレベルからサービスを削除します。以下の <service>
は削除したいサービスの名前です:
root #
rc-update delete <service> default
一覧表示
ランレベルと、それらに割り当てられたサービス (init スクリプト) の一覧を表示するために、root 権限を使用する必要はありません。
利用可能なすべての init スクリプトと、それらのランレベル (どれかに追加されていれば) を表示するには、rc-update show -v を使用してください:
user $
rc-update show -v
rc-update または rc-update show を実行すると、いずれかのランレベルに追加されている init スクリプトのみを表示するでしょう。
すべてのサービスの状態を確認するには、代わりに、rc-status コマンドを --servicelist
(-s
) オプション付きで使用することができます:
user $
rc-status --servicelist
名前付きランレベル
OpenRC のランレベルは /etc/runlevels 内のディレクトリとして実装されています。追加のランレベル (以下では <runlevel>
として示しています) は、次を使用して作成できます:
root #
install -d /etc/runlevels/<runlevel>
追加のランレベルは、代替のシステムスタートアッププロファイルを提供するのに便利です。
スタックされたランレベル
スタックされたランレベルは、ひとつまたは複数の他のランレベルの操作の継承を可能にするために使用されます。スタックされたランレベルを作成するために使用されるコマンドは rc-update -s です。ランレベルを他のランレベルに追加することで依存関係が作成され、対象のランレベルが開始または終了されたときに、それが依存するすべての (スタックされた) ランレベルにあるすべての init スクリプト (サービス) が開始または終了されるようになります。
ラップトップ上で場所に応じてネットワークサービスをまとめるために、スタックされたランレベルを使用する例が OpenRC/Stacked runlevel にあります。
Prefix
Gentoo Prefix は、Gentoo をあるオフセット (prefix とも呼ばれます) の中にインストールします。これを利用することで、ファイルシステム階層中の異なる場所に Gentoo をインストールすることができ、そのため、コンフリクトを回避することができます。オフセット配下にインストールされるということに加えて、Gentoo Prefix は非特権で実行されます。つまり、使用するのに root ユーザまたはその権限が必要ないということです。
オフセット ("prefix" の場所) を使用することで、多くの「主要でない」ユーザ層も、Gentoo Linux Portage ツリーのパッケージの大部分からメリットを享受することができるようになります。現時点で、次のシステムのユーザが Gentoo Prefix を成功裏に実行することができます: PPC および x86 上の Mac OS X、x86、x86_64 および ia64 上の Linux、Sparc、Sparc/64、x86 および x86_64 上の Solaris 10、x86 上の FreeBSD、PPC 上の AIX、x86 上 の Interix、x86 上の Windows (Interix の助けを借りて)、PARISC および ia64 上の HP-UX。
OpenRC runscript already support prefix-installed daemons, during the Summer of Code 2012 work will be done to implement full secondary/session daemon behavior to complete the overall feature set provided by Prefix.
試してみるためのチュートリアルが、OpenRC/Prefix にあります。
ホットプラグ
OpenRC は udev からの新しいハードウェアイベントなど、外部イベントによってトリガーすることもできます。以下はホットプラグサービスについて設定ファイルに書いてある内容です:
/etc/rc.conf
rc_hotplug# rc_hotplug controls which services we allow to be hotplugged.
# A hotplugged service is one started by a dynamic dev manager when a matching
# hardware device is found.
# Hotplugged services appear in the "hotplugged" runlevel.
# If rc_hotplug is set to any value, we compare the name of this service
# to every pattern in the value, from left to right, and we allow the
# service to be hotplugged if it matches a pattern, or if it matches no
# patterns. Patterns can include shell wildcards.
# To disable services from being hotplugged, prefix patterns with "!".
# If rc_hotplug is not set or is empty, all hotplugging is disabled.
# Example - rc_hotplug="net.wlan !net.*"
# This allows net.wlan and any service not matching net.* to be hotplugged.
# Example - rc_hotplug="!net.*"
# This allows services that do not match "net.*" to be hotplugged.
CGroups サポート
OpenRC バージョン 0.12 以降、cgroups のサポートを拡張しました。詳細については OpenRC/CGroups を参照してください。OpenRC 0.51 以降、unified cgroups (v2) はデフォルトで有効化されています。
Chroot サポート
root #
mkdir -p /lib64/rc/init.d
root #
ln -s /lib64/rc/init.d /run/openrc
root #
touch /run/openrc/softlevel
root #
emerge --oneshot sys-apps/openrc
/etc/rc.conf
OpenRC 設定ファイルrc_sys="prefix"
rc_controller_cgroups="NO"
rc_depend_strict="NO"
rc_need="!net !dev !udev-mount !sysfs !checkfs !fsck !netmount !logger !clock !modules"
サービスを開始しようとしたときに、システムが次のメッセージを報告してくるかもしれません:
* WARNING: <service> is already starting
これは次のコマンドを実行することで修復できるかもしれません:
root #
rc-update --update
User services
User services are services that run as the specific user they belong to. Starting with version 0.60, OpenRC has support for user services.
OpenRC user service support requires an XDG_RUNTIME_DIR
to be set, since user services store state in ${XDG_RUNTIME_DIR}/openrc/; thus, a mechanism for setting XDG_RUNTIME_DIR
is required. That could be sys-auth/elogind, the shell's rc files as well as any other method of creating the directory and setting the environment variable. While system OpenRC service scripts are loaded from /etc/init.d/, scripts for user services are loaded from /etc/user/init.d/. User configurations are located in /etc/user/conf.d/ respectively. Configuration options defined in ${XDG_CONFIG_HOME}/rc/conf.d/ override options set in /etc/user/conf.d/, and options set in ${XDG_CONFIG_HOME}/rc/rc.conf override those in /etc/rc.conf. If XDG_CONFIG_HOME
is unset, OpenRC uses
~/.config as a default value.
Lingering
In the context of systemd, lingering is a mechanism ensuring the presence of a user session for a specific user. A session is created on system startup and this session is guaranteed to persist until shutdown, even the user logs in or out. Thus, services run on behalf of this user are preserved throughout the entire runtime of the system. While lingering itself is implemented by the session daemon (logind
in case of systemd), there are methods to achieve the similar results on an OpenRC-based system.
Although sys-apps/elogind has an --enable-linger <user>
option that should work with the PAM-based auto-start, it is recommended to enable the OpenRC user-specific session that achieves the same effect.
Service start on boot (lingering)
To enable per-user services for a user (<user>
is the name of the user), create a symlink /etc/init.d/user.<name> pointing to /etc/init.d/user. This service starts an OpenRC user session that then handles all services enable for the user.
root #
ln -s /etc/init.d/user /etc/init.d/user.<user>
root #
rc-update add user.<user>
Enable a service for a user with:
user $
rc-update --user add <service>
The service to enable must be present in /etc/user/init.d. All OpenRC commands (rc-update
, rc-service
, rc-status
etc.) have a --user
(-U
) flag to act on the OpenRC user session instead of the system session.
Service start on login (no lingering)
The OpenRC session is only active while the user is logged in (see #lingering). As soon as the user logs out, the session is terminated.
PAM-based auto-start
The provided pam_openrc.so
can automatically start openrc on login. It's loaded from /etc/pam.d/system-login, and dynamically starts /etc/init.d/user script, multiplexed for the user logging in, which launches the openrc-user
daemon.
openrc-user
opens another pam session for the user, which will last as long as any given session using pam_openrc is active. It loads /etc/pam.d/openrc-user as the pam stack for the new session, then proceeds to launch the default
runlevel for the user via calling the user's login shell with -c
as an argument, and creating ${XDG_CONFIG_HOME}/rc/runlevels/default should it not exist.
In order to make use of the PAM-based auto-start, XDG_RUNTIME_DIR
must be set during the login process, either by a pam module or shell rc file.
システム統合
systemd との互換性
logind
構成によっては systemd-logind が必要な場合があります。Elogind は OpenRC とともに実行できるスタンドアローンの logind として、適切な代替になり得るでしょう。
tmpfiles.d
systemd は一時ファイルを管理するための特別な tmpfiles.d ファイル命名法を使用しています。sys-apps/systemd-tmpfiles は、OpenRC システムのためにスタンドアローンで同機能を提供します。今は非推奨ですが、OpenRC のために tmpfiles.d を解釈する機能を (今のところ) 提供する sys-apps/opentmpfiles もあります。
いずれも /sys または /proc 内の、再起動すると消えるエントリを管理するために使用できます。
udev と mdev
udev と mdev は、Gentoo で /dev を管理するために使用できるシステムです。かつては eudev も利用可能でしたが、今は削除されています。OpenRC 向けの udev は [udev sys-apps/systemd-utils[udev]] パッケージを介して利用可能ですが、Gentoo 上の OpenRC はどちらとの組み合わせでも機能するはずです。
古い Gentoo のインストールでは、メインの virtual/udev プロバイダとして udev を使用していました。これは bug #575718 によって eudev に変更されましたが、bug #807193 で udev に戻されました。しかしながら、rc サービスはどちらでも /etc/init.d/udev です。
組み込みシステムなどでの mdev の使用可能性については、mdev を参照してください。
BusyBox 統合
注意: この節は、実際に OpenRC で BusyBox を使う方法についての情報を欠いています。
現時点で、多数の BusyBox アプレットが OpenRC と互換性が無いことに注意してください。詳細は bug #529086 を参照してください。OpenRC を BusyBox とともに使用するには、セットアップのためにいくぶんかの作業が必要になるかもしれないことに警戒してください。BusyBox は組み込み用途により適しています。前の節の mdev に関する部分を参照してください。
完全な BusyBox を OpenRC のためのシェルとして使用することによって、BusyBox を OpenRC によって必要とされるユーザ空間ユーティリティ (init、シェル、awk、およびその他の POSIX ツール) のほとんどを置き換えるために使用できます [1]。通常なら fork/exec を発生させる呼び出しが回避され、全体のスピードが向上します。
Gentoo によって提供される SysV-init /etc/inittab ファイルは、BusyBox init と互換性がありません。以下は BusyBox と互換性のある inittab の例です:
/etc/inittab
BusyBox init と互換性のある inittab の例::sysinit:/sbin/openrc sysinit
::wait:/sbin/openrc boot
::wait:/sbin/openrc
BusyBox は、acpid や dhcp/dhcpcd などのサードパーティソフトウェアを置き換えるために使用できる、多数のアプレットを提供します。
using BusyBox with OpenRC にある OpenRC のドキュメンテーションを参照してください。
トラブルシューティング
クラッシュしたサービスを再起動する
OpenRC は、ステートフルな init スクリプトと自動再起動を提供するために、サービスの状態をランレベルで設定された状態に戻すことができます。
クラッシュしたサービスを default ランレベルから再起動するには、openrc を実行してください: クラッシュしたサービスは開始され、手動で実行されたサービスは停止されるでしょう。手動で開始したサービスの実行を継続させるには、openrc --no-stop か、短い形式の openrc -n を実行してください。
デフォルトでは、openrc はクラッシュしたサービスを再開 (restart) ではなく、開始 (start) させるでしょう。 これは /etc/rc.conf 内の rc_crashed_stop (デフォルト: NO) と rc_crashed_start (デフォルト: YES) オプションで制御できます。
クラッシュしたサービスを手動で回復する
プロセスが開始中にクラッシュした場合は、サービスを開始、停止、またはステータスを表示しようとしたときに、エラーまたは警告メッセージが表示されるでしょう。例えば、"docker" サービスを使用するときには:
root #
rc-service docker status
* status: crashed
root #
rc-service docker start
* WARNING: docker has already been started
root #
rc-service docker stop
* Caching service dependencies ... [ ok ] * Stopping docker ... * Failed to stop docker [ !! ] * ERROR: docker failed to stop
この状況を打開するには、サービスを zap してください:
root #
rc-service docker zap
関連項目
- OpenRC/CGroups — OpenRC includes support for cgroups.
- OpenRC/openrc-init — Open-RC's own init system
- OpenRC/Prefix — The following guideline applies to a Gentoo Prefix on RHEL-5.6 amd64 and on Debian 6.0 amd64, for other setups it should be similar.
- OpenRC/Stacked runlevel — a tutorial for setting up complicated networking with the help of stacked runlevel.
- OpenRC/supervise-daemon — OpenRC's daemon supervisor
- OpenRC/Users — an (incomplete) list of distributions and operating systems using OpenRC.
- /etc/local.d — /etc/local.d/ can contain small programs or light scripts to be run when the local service is started or stopped.
- Gentoo AMD64 ハンドブック - Init スクリプトシステム
- メインの OpenRC 設定ファイルである /etc/rc.conf は、OpenRC の設定について文書化した多数のコメントを含んでいます。
外部資料
OpenRC ドキュメンテーション
OpenRC は OpenRC 開発者によって保守されている、自身の有用なドキュメンテーションを持っています。Gentoo はデフォルトでは OpenRC のすべての機能を利用していないことに注意してください:
- README
- User Guide
- OpenRC init process guide - OpenRC の自身の init システム を使用する方法 (Gentoo のデフォルトでは使用していません)。
- agetty guide - OpenRC で agetty サービスを構成する (Gentoo のデフォルトでは、tty は sysvinit によって生成されます)。
- Using runit with OpenRC
- Using S6 with OpenRC
- Using supervise-daemon - 追加のプロセス監視。
- Using BusyBox with OpenRC
- Service script writing guide - 開発者またはパッケージ作成者向け。
- NEWS - 各リリースについての重要な情報。
- HISTORY - OpenRC が生まれた歴史。
Man pages
- openrc(8) - Stops and starts services for the specified runlevel.
- openrc-run(8) - Interpreter used to process OpenRC service scripts.
- rc-service(8) - Locate and run an OpenRC service with the given arguments.
- rc-status(8) - Show status info about runlevels.
- rc-update(8) - Add and remove services to and from a runlevel.