가상환경 설정

$ cd /my/working/dir

$ virtualenv -p python3 env35

$ cd env35

$ mkdir run

$ source bin/activate

$ pip install django gunicorn

$ django-admin startproject testproject

$ cd testproject

$ django-admin startapp testapp


디렉토리 구조

/my/working/dir


`-- env35
    |-- bin
    |  
    |-- include
    |   `-- python3.5m -> /usr/include/python3.5m
    |-- lib
    |   `-- python3.5
    |-- testproject
    |   |-- media
    |   |-- testproject
    |   |-- static
    |   |-- templates
    |   `-- testapp
    `-- run



gunicorn systemd 등록

$ sudo mkdir /run/gunicorn

$ sudo chown youurUserName.yourGroup /run/gunicorn

# sudo vi /etc/systemd/system/gunicorn.service

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
PIDFile=/run/gunicorn/pid
User=youurUserName
Group=yourGroup
WorkingDirectory=/my/working/dir/env35/testproject
ExecStart=/my/working/dir/env35/bin/gunicorn \
        --pid /run/gunicorn/pid \
        --workers 2 \
        --bind unix:/run/gunicorn/gunicorn.sock \
        testproject.wsgi:application

ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target


gunicorn 서비스 시작

$ sudo systemctrl enable gunicorn.service

$ sudo systemctl start gunicorn.service



+ Recent posts