Django開発で使用しているGunicornのコマンドリスト
- 投稿者: yoshitakakai
- 作成日: 2024年8月28日8:43
- 更新日: 2025年3月15日16:37
- カテゴリ: Gunicorn
- タグ: Webアプリ開発,
$ sudo pkill gunicorn # Gunicorn停止
$ ps ax|grep gunicorn # バックエンドサーバー状況確認
$ sudo systemctl daemon-reload # ※
$ sudo systemctl restart gunicorn # Gunicorn再起動
$ sudo lsof -i :8000 #ポートの競合チェック(やらなくてもいい)
※ sudo systemctl daemon-reload コマンドを実行すると、systemd がユニットファイルの変更を検知して再読み込みします。
おまけ
上記3つの入力は以下のようにまとめて実行することもできる。
$ sudo pkill gunicorn && sudo systemctl daemon-reload && sudo systemctl restart gunicorn
シェルスクリプトで実行したい?
#!/bin/bash
sudo pkill gunicorn
sudo systemctl daemon-reload
sudo systemctl restart gunicorn
echo "Gunicorn has been restarted successfully."
こんな感じのコードを書いて、適当にrestart.shみたいな名前をつけて、以下のように実行権限を付加した上で実行できるようにすれば、少しは効率が上がるかも。
$ chmod +x restart.sh
$ ./restart.sh