ubuntu, flask restful

Python 2018. 2. 26. 11:22

$ 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

Posted by 앤비
,