書式
start-stop-daemon [option...] command
説明
start-stop-daemon
はシステムレベルのプロセスの生成や停止を制御するために使用される。また、
適切なオプションを指定することで、実行中のプロセスを確認することができる。
Note: unless --pid or --pidfile are specified,
start-stop-daemon behaves similar to killall(1).
start-stop-daemon will scan the process table looking for any
processes which match the process name, parent pid, uid, and/or gid (if
specified). Any matching process will prevent --start from starting
the daemon. All matching processes will be sent the TERM signal (or the one
specified via --signal or --retry) if --stop is
specified. For daemons which have long-lived children which need to live
through a --stop, you must specify a pidfile.
コマンド
- -S, --start
[--] arguments
- 指定されたプロセスの存在を確認する。該当するプロセスが存在する場合、
start-stop-daemon
は何もせず、エラーステータス
1 を返して終了する
(--oknodo
が指定された場合は、0
を返す)。該当するプロセスが存在しない場合、
--exec
により、もしくは
--startas
が指定された場合はこれにより指定される実行ファイルを起動する。コマンドライン上で
--
以降に与えられた任意の引数は起動されるプログラムにそのまま引き渡される。
- -K, --stop
- 指定されたプロセスの存在を確認する。該当するプロセスが存在する場合、
start-stop-daemon は --signal
により指定されたシグナルをそのプロセスに送り、エラーステータス
0
を返して終了する。該当するプロセスが存在しない場合、
start-stop-daemon
はエラーステータス 1
を返して終了する(
--oknodo
が指定された場合は 0
を返す)。--retry
を指定した場合、start-stop-daemon
はそのプロセスが終了したことを確認する。
- -T, --status
- Check for the existence of a specified process, and returns an exit status
code, according to the LSB Init Script Actions (since version
1.16.1).
- -H, --help
- 使用方法に関する情報を表示し、終了する。
- -V, --version
- バージョンと著作権に関する情報を表示し、終了する。
オプション
- --pid pid
- Check for a process with the specified pid (since version 1.17.6).
The pid must be a number greater than 0.
- --ppid
ppid
- Check for a process with the specified parent pid ppid (since
version 1.17.7). The ppid must be a number greater than 0.
- -p, --pidfile
pid-file
- プロセスが pid-file
を作成したかどうかをチェックする。このオプションを単体で使用した場合、以前のプロセスが
pid-file
を削除できないまま終了してしまった際に、意図しないプロセスが動作中であると判断される場合があるため留意すること。
- -x, --exec
executable
- プロセスが指定した
executable
のインスタンスであるかどうかをチェックする。executable
引数は絶対パス名であること。インタプリタ型のスクリプトに対して指定した場合、executable
はインタプリタ自体を指してしまうため、期待する動作とならない点に留意すること。chroot
内で動作しているプロセスもマッチしてしまうため、これ以外の制約との組み合わせが必要となる点に注意すること。
- -n, --name
process-name
- プロセスが process-name
であるかどうかをチェックする。process-name
は通常プロセスのファイル名であるが、プロセス自身によって変更することも可能である。大半のシステムにおいて、この情報はカーネル内の
process comm name
から取得されるため、比較的短い名称である必要がある
(15
文字を超える名称は移植性がないと判断される)点に留意すること。
- -u, --user
username|uid
- プロセスが username
もしくは uid
で指定されたユーザの所有となっているかをチェックする。このオプションを単体で用いた場合、指定されたユーザの所有するすべてのプロセスが合致するかをチェックする点に留意すること。
- -g, --group
group|gid
- プロセスを開始する時点で、group
や gid を変更する。
- -s, --signal
signal
- --stop
と同時に指定することで、プロセスを停止するために送信するシグナルを指定する
(デフォルトは TERM)。
- -R, --retry
timeout|schedule
- --stop
と同時に指定することで、start-stop-daemon
にプロセスの終了を確認させる。これにより、マッチした実行中のプロセスが全て終了するまで繰り返し確認が行われる。プロセスが終了しなければ、スケジュールにより指定されたアクションが実行される。
schedule のかわりに
timeout
が指定されている場合、
signal/timeout/KILL/timeout
スケジュールが使われる。ここで
signal は --signal
で指定されるシグナルである。
スケジュール
schedule は、スラッシュ
(/)
で区切られた少なくとも
2
つの要素からなるリストである。それぞれの要素は、-signal-number
もしくは [-]signal-name
の場合は送るべきシグナル、
timeout
の場合はプロセスが終了するのを待つ秒数、
forever
の場合は必要な限り、残りの
schedule
を繰り返し適用することを意味する。
schedule
が終了し、forever
が指定されていない場合、
start-stop-daemon
はエラー状態 2
で終了する。schedule
が指定されている場合、--signal
で指定したシグナルは無視される。
- -a, --startas
pathname
- --start
と同時に指定することで、pathname
により指定されるプロセスを起動する。このオプションが指定されない場合、
--exec
に与えられる引数がデフォルトになる。
- -t, --test
- 実行しようとする処理内容を出力し,それに伴い適切な返り値が設定されるが、実際の処理は行わない。
- -o, --oknodo
- 処理が何も行われない
(又は、行なわれないと想定される)
場合、終了ステータス
1 のかわりに 0
を返す。
- -q, --quiet
- 情報メッセージを出力しない。エラーメッセージのみ出力する。
- -c, --chuid
username|uid[:group|gid]
- Change to this username/uid before starting the process. You can also
specify a group by appending a :, then the group or gid in the same
way as you would for the chown(1) command
(user:group). If a user is specified without a group,
the primary GID for that user is used. When using this option you must
realize that the primary and supplemental groups are set as well, even if
the --group option is not specified. The --group option is
only for groups that the user isn't normally a member of (like adding per
process group membership for generic users like nobody).
- -r, --chroot
root
- プロセスを起動する前に、root
に対して chdir と chroot
を実行する。pidfile は chroot
後に、書き出されることに注意すること。
- -d, --chdir
path
- Chdir to path before starting the process. This is done after the
chroot if the -r|--chroot option is set. When not specified,
start-stop-daemon will chdir to the root directory before starting
the process.
- -b,
--background
- Typically used with programs that don't detach on their own. This option
will force start-stop-daemon to fork before starting the process,
and force it into the background. Warning: start-stop-daemon cannot
check the exit status if the process fails to execute for any
reason. This is a last resort, and is only meant for programs that either
make no sense forking on their own, or where it's not feasible to add the
code for them to do this themselves.
- -C,
--no-close
- Do not close any file descriptor when forcing the daemon into the
background (since version 1.16.5). Used for debugging purposes to see the
process output, or to redirect file descriptors to log the process output.
Only relevant when using --background.
- -N, --nicelevel
int
- プロセスを起動する前にプロセスのプライオリティを変更する。
- -P, --procsched
policy:priority
- This alters the process scheduler policy and priority of the process
before starting it (since version 1.15.0). The priority can be optionally
specified by appending a : followed by the value. The default
priority is 0. The currently supported policy values are
other, fifo and rr.
- -I, --iosched
class:priority
- This alters the IO scheduler class and priority of the process before
starting it (since version 1.15.0). The priority can be optionally
specified by appending a : followed by the value. The default
priority is 4, unless class is idle, then
priority will always be 7. The currently supported values for
class are idle, best-effort and
real-time.
- -k, --umask
mask
- This sets the umask of the process before starting it (since version
1.13.22).
- -m,
--make-pidfile
- Used when starting a program that does not create its own pid file. This
option will make start-stop-daemon create the file referenced with
--pidfile and place the pid into it just before executing the
process. Note, the file will only be removed when stopping the program if
--remove-pidfile is used. Note: This feature may not work in
all cases. Most notably when the program being executed forks from its
main process. Because of this, it is usually only useful when combined
with the --background option.
- --remove-pidfile
- Used when stopping a program that does not remove its own pid file (since
version 1.17.19). This option will make start-stop-daemon remove
the file referenced with --pidfile after terminating the
process.
- -v, --verbose
- 詳細な情報を出力する。
終了ステータス
- 0
- 指定されたアクションが実行された。--oknodo
が指定された場合、何も行われなかった場合も意味する。これは、--start
が指定されたがマッチするプロセスが実行されていた場合、--stop
が指定されたがマッチするプロセスが存在しなかった場合に発生しうる。
- 1
- --oknodo
が指定されなかった場合に、何も行われなかった。
- 2
- --stop および --retry
が指定されたが、規定時間の最後まで到達したにも関わらず、プロセスがまだ実行されている。
- 3
- その他のエラー。
--status
コマンドを実行した際には、以下の戻り値が返される:
- 0
- プログラムは実行中である。
- 1
- プログラムは実行中でないが、pid
ファイルが存在している。
- 3
- プログラムは実行中でない。
- 4
- プログラムの状況を確認できない。
例
既に実行中でない場合に、food
デーモンを
(プロセス名
food、実行ユーザ food 、PID
情報を food.pid に格納で)
起動する。
-
start-stop-daemon --start --oknodo --user food --name food \
--pidfile /run/food.pid --startas /usr/sbin/food \
--chuid food -- --daemon
food に SIGTERM
を送信し、停止するまで
5 秒間待機する:
-
start-stop-daemon --stop --oknodo --user food --name food \
--pidfile /run/food.pid --retry 5
food
停止のためのカスタムスケジュールのデモ:
-
start-stop-daemon --stop --oknodo --user food --name food \
--pidfile /run/food.pid --retry=TERM/30/KILL/5
翻訳者
高橋 基信 <monyo@monyo.com>.
喜瀬 浩 <kise@fuyuneko.jp>. 関戸
幸一 <sekido@mbox.kyoto-inet.or.jp>. 鍋谷
栄展 <nabe@debian.or.jp>. 倉澤 望
<nabetaro@debian.or.jp>. 石川 睦
<ishikawa@linux.or.jp>. 鵜飼 文敏
<ukai@debian.or.jp>. 中野 武雄
<nakano@apm.seikei.ac.jp>.
翻訳校正
Debian JP Documentation ML <debian-doc@debian.or.jp>.