$ cd /home/service
$ git clone https://gyunseul9@bitbucket.org/gyunseul9/api_flask.git
$ virtualenv api_flask
$ cd api_flask
$ . bin/activate
$ pip3 install flask
$ pip3 install flask-restful
$ pip3 install uwsgi
$ pip3 freeze > requirements.txt
$ vi api.py
---
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class CreateUser(Resource):
def post(self):
return {'status':'success'}
api.add_resource(CreateUser,'/user')
if __name__ == '__main__':
app.run('0.0.0.0',debug=True)
---
$ python3 api.py
$ git add .
$ git commit -am "google, initialize api_flask"
$ git push
$ mkdir env
$ vi ./env/uwsgi_api.ini
---
[uwsgi]
chdir=/home/service/api_flask
chmod-socket=666
callable=app
module=api
socket=/tmp/uwsgi_api.sock
virtualenv=/home/service/api_flask
master=true
processes=5
max-requests=1000
harakiri=10
lazy-apps=true
logto=/var/log/uwsgi/uwsgi_api.log
enable-threads = true
---
$ vi run.sh
---
#!/bin/bash
source /home/service/api_flask/bin/activate
uwsgi --ini /home/service/api_flask/env/uwsgi_api.ini
---
$ chmod +x run.sh
$ vi /etc/nginx/sites-available/default
---
server {
listen 8080;
server_name 0.0.0.0;
location / {
try_files $uri @api;
}
location @api {
include uwsgi_params;
uwsgi_pass unix:/tmp/uwsgi_api.sock;
}
}
---
$ vi /etc/supervisor/conf.d/api.conf
---
[program:api]
command=/home/service/api_flask/run.sh
environment=HOME='/home/service',USER='service'
directory=/home/service/api_flask
autostart=true
autorestart=true
startretries=3
---
$ service nginx restart
$ cd /tmp
$ /home/service/api_flask/run.sh
ctrl + c
$ ls -al
$ service supervisor stop
$ service supervisor start
$ supervisorctl
'Python' 카테고리의 다른 글
python, stored-procedure, mysql, flask, run api (0) | 2018.03.02 |
---|---|
ubuntu, supervisor+uwsgi+nginx+python3 (0) | 2018.02.27 |
AWS Cloud, Python, Use sshtunneling to store rds data in a local database (0) | 2018.02.25 |
python, heroku, git, flask 샘플코드 (0) | 2018.01.27 |
python, alchemy 설정 (0) | 2018.01.20 |