デーモン動作に対応していないプログラムを root ではなく、ユーザー権限で起動・監視・停止などの管理を行うツールである。Pythonによって記述されており、安定した動作で可動する。
# git clone https://github.com/Supervisor/supervisor # cd supervisor # python setup.py install <- 但し python 2.7 以上が必要 # ln -s /usr/local/bin/supervisord /usr/bin/supervisord # ln -s /usr/local/bin/supervisorctl /usr/bin/supervisorctl # cp skel/sample.conf /etc/supervisord.conf
# mkdir /etc/supervisord.d # vi /etc/supervisord.conf <- 必要に応じて修正 [supervisord] logfile=/var/log/supervisor/supervisord.log pidfile=/var/run/supervisord.pid [include] files = supervisord.d/*.ini
以下の設定を行うとWEBから管理できるようになる。
[inet_http_server] port=127.0.0.1:9001 [supervisorctl] serverurl=unix:///var/tmp/supervisor.sock serverurl=http://127.0.0.1:9001
Centos6
# git clone https://github.com/Supervisor/initscripts # cd initscripts # cp redhat-init-equeffelec /etc/rc.d/init.d/supervisord # chmod 755 /etc/rc.d/init.d/supervisord # chkconfig --add supervisord # service supervisord start # service supervisord status # service supervisord stop
Centos7
# vi /etc/systemd/system/supervisord.service [Unit] Description=Supervisor process control system for UNIX Documentation=http://supervisord.org After=network.target [Service] ExecStart=/usr/bin/supervisord -n -c /etc/supervisord.conf ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown ExecReload=/usr/bin/supervisorctl $OPTIONS reload KillMode=process Restart=on-failure RestartSec=50s [Install] WantedBy=multi-user.target
起動と停止と登録
# systemctl start supervisord # systemctl status supervisord # systemctl stop supervisord # systemctl enable supervisord.service
# sh -c "echo '/var/log/supervisor/*.log { missingok weekly notifempty nocompress }' > /etc/logrotate.d/supervisor"
システム管理コマンドの機能一覧を表示する。
# supervisorctl help
Suprvisorでは設定ファイルに登録したプロセス毎に管理される。以後それらを設定プロセスと呼ぶ。
機能 | 例 | 概要 |
add | supervisorctl add myapp | デーモンの管理対象として設定プロセスを追加 |
avail | supervisorctl avail | Supervisorが管理している設定プロセスの詳細を確認 |
clear | supervisorctl clear myapp | 設定プロセスのログをクリア |
fg | supervisorctl fg myapp | 設定プロセスをフォアグラウンドに切り替える。※基本禁止 |
tail | supervisorctl tail myapp | 設定プロセスのログを表示。mailtail にすると supervisorのログ表示 |
pid | supervisorctl pid all | 設定プロセスのPIDを表示 |
reload | supervisorctl reload | Supervisor自身を再起動。各登録設定プロセスもすべて再起動 |
remove | supervisorctl remove myapp | addで登録された設定プロセスの登録を削除 |
restart | supervisorctl restart myapp | 指定した設定プロセスの再起動を行う |
shutdown | supervisorctl shutdown | supervisor自身のデーモンを終了させる |
start | supervisorctl start myapp | 設定プロセスの実行開始 |
stop | supervisorctl stop myapp | 設定プロセスの実行終了 |
status | supervisorctl status myapp | 設定プロセスのステータス確認 |
update | supervisorctl update myapp | 設定プロセスの設定を読み直す |