AWS
supervisord
死活監視

Amazon Linuxにsupervisordをインストールしてサービス監視する方法

EC2(Amazon Linux)上にSupervisordをインストールしてサービスの起動や監視を行う方法。

Python PIPのインストール

sudo yum install -y python-pip python-dev

setup supervisord

remiとかでyumでインストールもできるけど、
今回はpipで最新バージョンをインストールする。

$ sudo pip install supervisord
$ sudo mkdir /etc/supervisord.d/

設定ファイルの追加

$ sudo sh -c "echo_supervisord_conf > /etc/supervisord.conf"
# /etc/supervisord.confの末尾に以下を追加する
[include]
files = supervisord.d/*.conf

起動スクリプトを作成

$ wget https://raw.githubusercontent.com/kazupyong/conf/master/init.d/supervisord
$ sudo mv ./supervisord /etc/init.d/supervisord
$ sudo chown root.root /etc/init.d/supervisord
$ sudo chmod +x /etc/init.d/supervisord

起動確認

$ sudo chkconfig supervisord on
$ sudo service supervisord start

(参考)Redashの死活監視設定

$ sudo vi /etc/supervisord.d/redash.conf
[inet_http_server]
port = 127.0.0.1:9001

[program:redash_server]
command=/opt/redash/current/bin/run gunicorn -b 127.0.0.1:5000 --name redash -w 4 --max-requests 1000 redash.wsgi:app
directory=/opt/redash/current
process_name=redash_server
environment=PATH="/usr/local/bin:%(ENV_PATH)s"
user=redash
numprocs=1
autostart=true
autorestart=true

# There are two queue types here: one for ad-hoc queries, and one for the refresh of scheduled queries
# (note that "scheduled_queries" appears only in the queue list of "redash_celery_scheduled").
# The default concurrency level for each is 2 (-c2), you can increase based on your machine's resources.

[program:redash_celery]
command=/opt/redash/current/bin/run celery worker --app=redash.worker --beat -c2 -Qqueries,celery --maxtasksperchild=10 -Ofair
directory=/opt/redash/current
process_name=redash_celery
environment=PATH="/usr/local/bin:%(ENV_PATH)s"
user=redash
numprocs=1
autostart=true
autorestart=true

[program:redash_celery_scheduled]
command=/opt/redash/current/bin/run celery worker --app=redash.worker -c2 -Qscheduled_queries --maxtasksperchild=10 -Ofair
directory=/opt/redash/current
process_name=redash_celery_scheduled
environment=PATH="/usr/local/bin:%(ENV_PATH)s"
user=redash
numprocs=1
autostart=true
autorestart=true

参考にした記事

http://supervisord.org/configuration.html