LoginSignup
44
39

More than 3 years have passed since last update.

Supervisorの基本コマンド

Last updated at Posted at 2019-11-21

Supervisorとは

常時起動させたいスクリプトなど、デーモンプロセスとして動かしたいときに使うプロセス管理/デーモン化※1 のツール。
公式ドキュメント: http://supervisord.org/

※1 そもそもデーモンとは
デーモン (英語: Daemon) は、UNIX, Linux, MacOSXなどUnix系のマルチタスクオペレーティングシステム (OS) において動作するプロセス(プログラム)で、主にバックグラウンドで動作するプロセス。ユーザが直接対話的に制御するプログラムもデーモンとして作ることができる。典型的なデーモンは名前の最後尾に "d" が付く。
https://ja.wikipedia.org/wiki/%E3%83%87%E3%83%BC%E3%83%A2%E3%83%B3_(%E3%82%BD%E3%83%95%E3%83%88%E3%82%A6%E3%82%A7%E3%82%A2)

コマンドについて

  • Supervisorの操作は supervisorctl コマンドで行う
    • supervisord コマンドは Supervisor そのものを立ち上げるコマンドなので操作コマンドではない
  • supervisorctlによって supervisor そのものや、supervisor が立ち上げている各種プロセスを操作することができる
  • $ supervisorctl help によってコマンド一覧を確認することができる
$ supervisorctl help

default commands (type help <topic>):
=====================================
add    exit      open  reload  restart   start   tail
avail  fg        pid   remove  shutdown  status  update
clear  maintail  quit  reread  signal    stop    version

検証用環境のバージョンを確認してみる

$ supervisorctl version
4.0.4

主要な supervisorctl コマンド

supervisorctl add

  • プロセス/グループの構成内の更新をアクティブにする
  • Supervisorのデーモンの管理対象を追加

supervisorctl update

  • 設定ファイルを読み込み直し、必要に応じてaddによる設定の適用や、removeによるプロセスを削除する

指定方法は以下の通り

update          Reload config and add/remove as necessary, and will restart affected programs
update all      Reload config and add/remove as necessary, and will restart affected programs
update <gname> [...]    Update specific groups

supervisorctl start

  • 指定したプロセスを開始する
  • この時点で reread で読み込まれている設定変更のみ適用される

指定方法は以下の通り

start <name>        Start a process
start <gname>:*     Start all processes in a group
start <name> <name> Start multiple processes or groups
start all       Start all processes

例:$ supervisorctl start all

supervisorctl stop

  • 各プロセスを停止する
  • 停止したプロセスの再起動は前述したstartを使用する

指定方法は以下の通り

stop <name>             Stop a process
stop <gname>:*          Stop all processes in a group
stop <name> <name>      Stop multiple processes or groups
stop all                Stop all processes

例:$ supervisorctl stop all

supervisorctl reread

  • add/remove なしに Supervisor の設定ファイル(デーモンの構成ファイル)を再読み込みする
    • 再読み込みのみで、この段階では変更した設定は各プロセスやグループに適用されない
    • 適用する場合は restart や add を実行する必要がある

supervisorctl restart

  • プロセスやプロセスグループなどを指定して再起動する
  • この時点で reread や update などで読み込まれている設定変更のみ適用される

指定方法は以下の通り

restart <name>      Restart a process
restart <gname>:*   Restart all processes in a group
restart <name> <name>   Restart multiple processes or groups
restart all     Restart all processes

supervisorctl reload

  • Supervisorのデーモンを一度停止して立ち上げ直す
  • 立ち上げ時に設定ファイルが読み込まれるため、変更があればそれが適用されたプロセスが起動される

supervisorctl pid

  • Supervisorが管理しているプロセスのPIDを表示する

指定方法は以下の通り

pid                     Get the PID of supervisord.
pid <name>              Get the PID of a single child process by name.
pid all                 Get the PID of every child process, one per line.

supervisorctl tail

  • プロセスの標準出力/標準エラー出力する
$ supervisorctl tail -f [プロセス名]

参考
https://papix.hatenablog.com/entry/2015/08/05/131113
https://qiita.com/yushin/items/15f4f90c5663710dbd56

44
39
1

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
44
39