Monitor deployment playbook (#133)

* Introduced monitor deployment playbook

* Timeouts

* dai deployment block

* wetc deployment blocks

* Corrected path

* Typo.

* Added monitor to execution readme.

* Monitor port.

* Check on start

* Timeouts

* check-and-start
This commit is contained in:
Przemyslaw Rzad 2019-07-09 19:26:40 +02:00 committed by GitHub
parent 4281adfd95
commit 3f27b98b8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 164 additions and 4 deletions

@ -42,9 +42,13 @@ cp hosts.yml.example hosts.yml
<host_ip_C>:
ansible_user: <user>
#syslog_server_port: "<protocol>://<ip>:<port>"
monitor:
hosts:
<host_ip_B>:
ansible_user: <user>
```
The config above would install the Oracle on `<host_ip_A>`, UI on `<host_ip_C>`, and both Oracle and UI on `<host_ip_B>`.
The config above would install the Oracle on `<host_ip_A>`, UI on `<host_ip_C>`, and both Oracle, UI and Monitor on `<host_ip_B>`.
Example config for installing only UI:
```yaml

@ -45,6 +45,7 @@ Component | Service Name
--- | ---
Oracle | poabridge
UI | tokenbridge-ui
Monitor | tokenbridge-monitor
Use the default `SysVinit` commands to `start`, `stop`, `restart`, and `rebuild` the service and to check the `status` of the service.

@ -39,3 +39,12 @@ UI_HOME_EXPLORER_ADDRESS_TEMPLATE: https://blockscout.com/poa/dai/address/%s
UI_FOREIGN_EXPLORER_ADDRESS_TEMPLATE: https://blockscout.com/eth/mainnet/address/%s
UI_HOME_GAS_PRICE_FALLBACK: 1000000000
UI_FOREIGN_GAS_PRICE_FALLBACK: 10000000000
## Monitor
MONITOR_PORT: 3003
MONITOR_HOME_DEPLOYMENT_BLOCK: 759
MONITOR_FOREIGN_DEPLOYMENT_BLOCK: 6478417
MONITOR_GAS_LIMIT: 300000
MONITOR_GAS_PRICE_FALLBACK: 21
MONITOR_LEFT_TX_THRESHOLD: 100
MONITOR_CRON_SCHEDULE: "* * * * *"

@ -39,3 +39,12 @@ UI_HOME_EXPLORER_ADDRESS_TEMPLATE: https://blockscout.com/poa/sokol/address/%s
UI_FOREIGN_EXPLORER_ADDRESS_TEMPLATE: https://blockscout.com/eth/kovan/address/%s
UI_HOME_GAS_PRICE_FALLBACK: 1000000000
UI_FOREIGN_GAS_PRICE_FALLBACK: 1000000000
## Monitor
MONITOR_PORT: 3003
MONITOR_HOME_DEPLOYMENT_BLOCK: 0
MONITOR_FOREIGN_DEPLOYMENT_BLOCK: 0
MONITOR_GAS_LIMIT: 300000
MONITOR_GAS_PRICE_FALLBACK: 21
MONITOR_LEFT_TX_THRESHOLD: 100
MONITOR_CRON_SCHEDULE: "* * * * *"

@ -39,3 +39,12 @@ UI_HOME_EXPLORER_ADDRESS_TEMPLATE: https://blockscout.com/etc/mainnet/address/%s
UI_FOREIGN_EXPLORER_ADDRESS_TEMPLATE: https://blockscout.com/eth/mainnet/address/%s
UI_HOME_GAS_PRICE_FALLBACK: 15000000000
UI_FOREIGN_GAS_PRICE_FALLBACK: 10000000000
## Monitor
MONITOR_PORT: 3003
MONITOR_HOME_DEPLOYMENT_BLOCK: 7703292
MONITOR_FOREIGN_DEPLOYMENT_BLOCK: 7412459
MONITOR_GAS_LIMIT: 300000
MONITOR_GAS_PRICE_FALLBACK: 21
MONITOR_LEFT_TX_THRESHOLD: 100
MONITOR_CRON_SCHEDULE: "* * * * *"

@ -11,3 +11,7 @@ sokol-kovan:
127.0.0.1:
ansible_user: ubuntu
#syslog_server_port: "udp://127.0.0.1:514"
monitor:
hosts:
127.0.0.1:
ansible_user: ubuntu

@ -0,0 +1,2 @@
dependencies:
- role: common

@ -0,0 +1,4 @@
- name: Launch container
shell: docker-compose up -d
args:
chdir: "{{ bridge_path }}/monitor"

@ -0,0 +1,3 @@
- include_tasks: pre_config.yml
- include_tasks: jumpbox.yml
- include_tasks: servinstall.yml

@ -0,0 +1,4 @@
- name: Install .env config
template:
src: .env.j2
dest: "{{ bridge_path }}/monitor/.env"

@ -0,0 +1,17 @@
# This role creates a tokenbridge-monitor service which is designed to manage docker-compose monitor deployment.
# /etc/init.d/tokenbridge-monitor start, status, stop, restart - does what the services usually do in such cases.
# /etc/init.d/tokenbridge-monitor rebuild - builds a new monitor deployment from scratch.
---
- name: "Set the service"
template:
src: tokenbridge-monitor.j2
dest: "/etc/init.d/tokenbridge-monitor"
owner: root
mode: 755
- name: "Start/Enable the service"
service:
name: "tokenbridge-monitor"
state: started
enabled: yes
use: service

@ -0,0 +1,12 @@
HOME_RPC_URL={{ HOME_RPC_URL }}
FOREIGN_RPC_URL={{ FOREIGN_RPC_URL }}
HOME_BRIDGE_ADDRESS={{ HOME_BRIDGE_ADDRESS }}
FOREIGN_BRIDGE_ADDRESS={{ FOREIGN_BRIDGE_ADDRESS }}
HOME_DEPLOYMENT_BLOCK={{ MONITOR_HOME_DEPLOYMENT_BLOCK }}
FOREIGN_DEPLOYMENT_BLOCK={{ MONITOR_FOREIGN_DEPLOYMENT_BLOCK }}
GAS_PRICE_SPEED_TYPE={{ HOME_GAS_PRICE_SPEED_TYPE }}
GAS_LIMIT={{ MONITOR_GAS_LIMIT }}
GAS_PRICE_FALLBACK={{ MONITOR_GAS_PRICE_FALLBACK }}
LEFT_TX_THRESHOLD={{ MONITOR_LEFT_TX_THRESHOLD }}
PORT={{ MONITOR_PORT }}
CRON_SCHEDULE={{ MONITOR_CRON_SCHEDULE }}

@ -0,0 +1,76 @@
#! /bin/bash
### BEGIN INIT INFO
# Provides: tokenbridge-monitor
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
WORKDIR="{{ '/home/' + compose_service_user | default('poadocker') + '/' + bridge_path + '/monitor' if bridge_path[:1] != "/" else bridge_path + '/monitor' }}"
start(){
echo "Starting TokenBridge Monitor.."
cd $WORKDIR
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose down -v
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose rm -fv
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose up --detach
}
stop(){
echo "Stopping TokenBridge Monitor.."
cd $WORKDIR
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose down -v
sleep 2
}
status(){
echo "TokenBridge Monitor status:"
cd $WORKDIR
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose ps
}
rebuild(){
echo "Rebuild TokenBridge Monitor.."
cd $WORKDIR
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose down -v
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose rm -fv
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose up --detach --force-recreate --no-deps --build
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
echo "Restarting TokenBridge Monitor.."
stop
start
;;
rebuild)
rebuild
;;
*)
echo $"Usage: $0 {start|stop|restart|rebuild|status}"
exit 1
;;
esac
exit 0

@ -8,3 +8,8 @@
become: true
roles:
- { role: ui }
- name: Install Monitor
hosts: monitor
become: true
roles:
- { role: monitor }

@ -14,4 +14,4 @@ RUN mv ./contracts/build ./ && rm -rf ./contracts/* ./contracts/.[!.]* && mv ./b
COPY ./monitor ./monitor
WORKDIR /mono/monitor
CMD echo "To start the monitor run:" \
"yarn start"
"yarn check-and-start"

@ -10,4 +10,4 @@ services:
environment:
- NODE_ENV=production
restart: unless-stopped
entrypoint: yarn start
entrypoint: "yarn check-and-start"

@ -4,8 +4,9 @@
"description": "",
"main": "index.js",
"scripts": {
"check-all": "node checkWorker.js && node checkWorker2.js",
"check-all": "timeout -s 9 5m node checkWorker.js && timeout -s 9 5m node checkWorker2.js",
"start": "node index.js",
"check-and-start": "yarn check-all && yarn start",
"lint": "eslint . --ignore-path ../.eslintignore",
"lint:fix": "eslint . --fix"
},