LoginSignup
3
2

More than 1 year has passed since last update.

デーモン化したgunicornのプロセスの起動、停止、確認をするBashスクリプト

Last updated at Posted at 2021-07-05

image.gif

環境

  • Ubuntu 20.04.2 LTS
  • GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
  • Python 3.8.10 (venv)
fastapi==0.65.2
gunicorn==20.1.0
setproctitle==1.2.2
uvicorn==0.14.0

パッケージのインストール

pip install fastapi
pip install gunicorn
pip install setproctitle
pip install uvicorn

使い方

ファイルの設定

  • gunicornの設定ファイル単位で、起動、停止が行える構成
├── gunicorn_config            <-- gunicorn設定ファイル
│   ├── guni_conf_prod.py
│   └── guni_conf_staging.py
├── gunidaemonctl              <-- Bash script
├── main.py                    <-- Python Web app for prod
└── main_fast_api.py           <-- Python Web app for staging

開始

  • 以下はステージングを起動する例
./gunidaemonctl start guni_conf_staging

停止

./gunidaemonctl stop guni_conf_staging

プロセス一覧

  • masterプロセスとworkerプロセスの一覧を確認した例
./gunidaemonctl ps guni_conf_staging

ubuntu 1001 0.8 2.2 0 0 ? S 12:10 0:00 gunicorn: master [guni_conf_staging]
ubuntu 1002 2.4 3.3 0 0 ? S 12:10 0:00 gunicorn: worker [guni_conf_staging]
ubuntu 1003 2.4 3.3 0 0 ? S 12:10 0:00 gunicorn: worker [guni_conf_staging]

マスタープロセスIDの確認

./gunidaemonctl pid guni_conf_staging

master pid:
1001

Bash スクリプト (github)

免責事項

  • 細心の注意を払って作成していますが、
  • 本スクリプトを使用して発生したいかなる損害に対して
  • 作者は一切責任を追いません。

リンク

3
2
0

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
3
2