LoginSignup
3
5

More than 5 years have passed since last update.

gunicorn_djangoの起動とログ取得設定

Posted at

環境:Amazon EC2, Amazon Linux

手動コマンドで環境の起動

$ workon app_env
$ gunicorn_django -b localhost:8081 --log-level=debug

起動ファイルでの起動

gunicornの起動設定ファイルを用意する
参考:http://dat.plastica-romantica.com/log699.html

$ sudo mkdir /var/log/gunicorn
$ sudo chown ec2-user:ec2-user /var/log/gunicorn
run_gunicorn_django.sh
#!/bin/bash
SERVER=localhost
PORT=8081
LOGFILE=/var/log/gunicorn/django_app.log
LOGDIR=$(dirname $LOGFILE)
NUM_WORKERS=3 #recommended formula here is 1 + 2 * NUM_CORES
USER=ec2-user
cd /opt/django/app_name
source /home/$USER/.virtualenvs/app_env/bin/activate
test -d $LOGDIR || mkdir -p $LOGDIR
exec gunicorn_django -b $SERVER:$PORT -w $NUM_WORKERS --log-level=debug --log-file=$LOGFILE 2>>$LOGFILE  --user=$USER

gunicornの起動

$ ./run_gunicorn_django.sh &

ログを見る

$ tail -f /var/log/gunicorn/django_app.log
3
5
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
5