updated myems-api installation

pull/76/MERGE
13621160019@163.com 2021-10-28 12:23:27 +08:00
parent 58729e671d
commit 8353ca2b88
5 changed files with 22 additions and 15 deletions

View File

@ -26,7 +26,7 @@ python-decouple
```bash
pip install -r requirements.txt
chmod +x run.sh
run.sh
./run.sh
```
## Installation
@ -55,8 +55,8 @@ python3 setup.py install
```bash
cd ~/tools
wget https://cdn.mysql.com/archives/mysql-connector-python-8.0/mysql-connector-python-8.0.23.tar.gz
tar xzf mysql-connector-python-8.0.20.tar.gz
cd ~/tools/mysql-connector-python-8.0.20
tar xzf mysql-connector-python-8.0.23.tar.gz
cd ~/tools/mysql-connector-python-8.0.23
python3 setup.py install
```
@ -145,13 +145,20 @@ Create .env file based on example.env and edit the .env file if needed:
cp /myems-api/example.env /myems-api/.env
nano /myems-api/.env
```
Change the listening port (default is 8000) in gunicorn.socket:
Check or change the listening port (default is 8000) in myems-api.service and myems-api.socket:
```bash
nano /myems-api/myems-api.service
```
```
ExecStart=/usr/local/bin/gunicorn -b 0.0.0.0:8000 --pid /run/myems-api/pid --timeout 600 --workers=4 app:api
```
```bash
nano /myems-api/myems-api.socket
```
```bash
ListenStream=0.0.0.0:8000
```
Add port to firewall:
```bash
ufw allow 8000
```

View File

@ -15,8 +15,8 @@ class VersionItem:
@staticmethod
def on_get(req, resp):
result = {"version": 'MyEMS v1.1.2',
"release-date": '202104023',
result = {"version": 'MyEMS v1.3.2',
"release-date": '2021-10-22',
"website": "https://myems.io"}
resp.body = json.dumps(result)

View File

@ -83,7 +83,7 @@ mysql> show databases; // 查看数据库是否导入OK
```
### 3.部署mymes-api服务
安装一堆python依赖库
安装python依赖库
```shell
# 安装anytree
$ cd ~/tools
@ -136,10 +136,10 @@ $ source ~/.zshrc
### 4.运行myems-api服务
```shell
$ git clone https://github.com/kuuyee/myems-api.git
$ cd myems-api
$ gunicorn -b 127.0.0.1:8000 app:api
$ cd myems/myems-api
$ gunicorn -b 0.0.0.0:8000 app:api
[2021-02-16 22:21:46 +0800] [3252] [INFO] Starting gunicorn 20.0.4
[2021-02-16 22:21:46 +0800] [3252] [INFO] Listening at: http://127.0.0.1:8000 (3252)
[2021-02-16 22:21:46 +0800] [3252] [INFO] Listening at: http://0.0.0.0:8000 (3252)
[2021-02-16 22:21:46 +0800] [3252] [INFO] Using worker: sync
[2021-02-16 22:21:46 +0800] [3253] [INFO] Booting worker with pid: 3253
@ -148,12 +148,12 @@ $ gunicorn -b 127.0.0.1:8000 app:api
### 5.验证myems-api服务
打开浏览器访问[http://localhost:8000/version](http://localhost:8000/version)
打开浏览器访问[http://0.0.0.0:8000/version](http://0.0.0.0:8000/version)
如果看到如下输出就表示服务启动正常。
```json
{
"version": "MyEMS 1.0.3 (Community Edition)",
"release-date": "20210215",
"version": "MyEMS 1.3.2",
"release-date": "2021-10-22",
"website": "https://myems.io"
}
```

View File

@ -8,7 +8,7 @@ PIDFile=/run/myems-api/pid
User=root
Group=root
WorkingDirectory=/myems-api
ExecStart=/usr/local/bin/gunicorn --pid /run/myems-api/pid --timeout 600 --workers=4 app:api
ExecStart=/usr/local/bin/gunicorn -b 0.0.0.0:8000 --pid /run/myems-api/pid --timeout 600 --workers=4 app:api
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true

View File

@ -1,3 +1,3 @@
#!/bin/sh
gunicorn --pid pid --timeout 600 --workers=4 app:api
gunicorn -b 0.0.0.0:8000 --pid pid --timeout 600 --workers=4 app:api