LoginSignup
1
1

More than 3 years have passed since last update.

Django/Flaskでソース変更後のリロード

Last updated at Posted at 2020-12-14

Djangoでサイトを作ってサーバーにあげられたのは良いもののgit pullをしてからのソース変更を反映する仕方がわからなかったのですが、調べたら出てきたので備忘録的に残します。

なお、デプロイの仕方については、@kantackyさんの記事を参考にさせていただきました。この場を借りてお礼申し上げます。とてもわかりやすかったです。

Djangoのデプロイで追い詰められているあなたへ。Ubuntu18.04+NginxでDjango2.2デプロイ完全版

追記

Flaskでも同様にリロードできたので含めておきます。

前提条件

Ubuntu 20.04 amd64
Nginx 1.18.0
Gunicorn 20.0.4
Python 3.8.5
Django 3.1.2
(Flask 1.1.2)

※プロジェクトをgitで管理していることを前提とする

手順

サーバーが起動している場合

git pull

まずはソースをgitからpullします。

sudo git pull

privateで管理している場合はこの後にパスワードなど諸々を打ち込んでpullしてください。

gunicornのkill

一旦gunicornをkillします。こちらのサイトを参考にしました。

sudo killall gunicorn

リロードなど

この後はもろもろのリロードを行います。

sudo systemctl daemon-reload

sudo systemctl restart nginx
sudo systemctl restart YourProjectName

ここは脳死状態でやったため、もしかしたら必要ない項目も紛れているかもしれません。

サーバーが停止していた場合

git pull

ここは起動している場合と同じです。

sudo git pull

privateで管理している場合はこの後にパスワードなど諸々を打ち込んでpullしてください。

リロードなど

ここが起動している場合と異なります。

sudo systemctl daemon-reload

sudo systemctl start nginx
sudo systemctl enable nginx

sudo systemctl start YourProjectName
sudo systemctl enable YourProjectName

つまり、全てstartし直すということです!

おわりに

今後は自動でリロードする設定をできたらいいなと...

1
1
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
1
1