LoginSignup
0
0

More than 5 years have passed since last update.

upstart の「start on stopped rc RUNLEVEL=[345]」ってどういう意味?

Posted at

調べた時のメモ。
upstart の設定ファイルに「start on stopped rc RUNLEVEL=[345]」と書いてあったがどのような意味かわからず、調べた時のメモ。

結論

  • rc job が停止(stopped)したら設定ファイルに記載されたジョブを実行(start)する
  • ランレベルが 3 or 4 or 5 の時のみ実行される
  • rc job は SysVinit のスクリプト群であり、SysVinit のスクリプト群である

upstart とは

upstart Overview

Upstart is an event-based replacement for the /sbin/init daemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running.

boot 時の タスクやサービスの起動を処理する /sbin/init デーモンの置き換え変えるためのイベントベースのもの。

調査内容

まずは upstart の Getting Started を見る。

Getting Started

Your job is now able to be started and stopped manually by a system administrator, however you also probably want it to be started and stopped automatically when events are emitted.

手動で起動停止も出来るが、event が emit されたときに 自動で起動・停止も出来る、と。

You list the events you want to start your job with start on, and the events that stop your job with stop on.

start on もしくは stop onというのを書ける。
今回、start on なので「何かしらのイベントがあったら exec を実行して起動」させるという意味になる。

もう少し例を見つつ確認したいので cookbook を見てみる。
以下はstart on stopped job-Bとなっている。

11.25.1 Simple Mutual Exclusion

# /etc/init/job-A.conf
start on stopped job-B

script
  # do something when job-B is stopped
end script

コメントにある通りで、上記のような書き方の場合、 job-B が終了したら job-A を実行するという意味になる。
今回も start on stopped となっていることから「何かしらのイベントが終わったら exec を実行する」という意味となる。

また、他にもいい例があった。

8.1 Really understanding start on and stop on

# /etc/init/alsa-mixer-save.conf
start on starting rc RUNLEVEL=[06]

"Run when the rc job emits the starting(7) event, but only if the environment variable RUNLEVEL equals either 0 (halt) or 6 (reboot)".

rc job がスタートしたら実行する。ただし、RUNLEVEL 環境変数が0もしくは6の場合のみ、と。

これを今回のものに置き換えると「rc job が停止したら実行する。ただし、ランレベルが 3 or 4 or 5の時に限る」と。

じゃあこの「rc job」は何なのか、というのも書いてあった。

8.1.1 The rc Job

/etc/init/rc.conf
# /etc/init/rc.conf
start on runlevel [0123456]
stop on runlevel [!$RUNLEVEL]

export RUNLEVEL
export PREVLEVEL

console output
env INIT_VERBOSE

task

exec /etc/init.d/rc $RUNLEVEL

"Run the SysV init script as /etc/init.d/rc $RUNLEVEL when telinit(8) emits the runlevel(7) event for any runlevel".

SysV init スクリプト(/etc/init.d/rc)に 引数RUNLEVEL を渡して telinit イベント発生時に実行する。イベントはどのランレベルでも実行される。
/etc/init.d/rcの中身を見ると /etc/rc.d/rc/etc/rc$runlevel.d/S*というようになっていた。つまり、上記は SysV init スクリプト群を実行するということになる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0