supervisord
知っていますか。
デーモン化するやつです。
これでスタートとかすると、起動します。
ストップとかすると止まります。
なんと、スーパーユーザじゃなくて出来ます。
手順
今回は、pythonのpyramidフレームワークでWEBアプリを作ってデーモン化します
仮想環境の作成
python3 -m venv env3
source env3/bin/activate
使用するライブラリのインストール
pip install pyramid
pip install mr.laforge
pip install supervisor
使用できるpyramidのテンプレートを確認する
今回はstarterでやろう
pcreate --list-templates
Available scaffolds:
alchemy: Pyramid project using SQLAlchemy, SQLite, URL dispatch, and Jinja2
starter: Pyramid starter project using URL dispatch and Jinja2
zodb: Pyramid project using ZODB, traversal, and Chameleon
プロジェクトの作成してインストール
pcreate -t starter hello
cd hello
pip install -e .
通常起動を確認する
pserve development.ini

supervisord.conf作成
[supervisord]
childlogdir = log
logfile = supervisord.log
logfile_maxbytes = 50MB
logfile_backups = 10
loglevel = info
pidfile = supervisord.pid
minfds = 1024
umask = 022
nodaemon = false
nocleanup = false
[inet_http_server]
port = 127.0.0.1:7001
username =
password =
[supervisorctl]
serverurl = http://localhost:7001
username =
password =
[ctlplugin:laforge]
supervisor.ctl_factory = mr.laforge.controllerplugin:make_laforge_controllerplugin
[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
[program:hello]
command = /Users/xxx/env3/bin/pserve /Users/xxx/hello/development.ini
process_name = hello
directory = /Users/xxx/hello/
priority = 10
numprocs = 1
redirect_stderr = true
autostart = false
supervisorの起動
こちらでsupervisordが立ち上がります
suppervisord -c supervisord.conf
supervisorctlの対話モードに入ります
supervisorctl
supervisorctlの使い方
これで、デーモン化した、pyramidが起動します。http://localhost:6543/
supervisor> start hello
これで、デーモン化した、pyramidが終了します。
supervisor> stop hello
対話型supervisorctlから抜けます。
supervisor> exit
これで、supervisorctlを終了します。
supervisor> shutdown