diff --git a/explorer.yml b/explorer.yml new file mode 100644 index 0000000..814e655 --- /dev/null +++ b/explorer.yml @@ -0,0 +1,102 @@ +--- +- name: Create explorer security group + hosts: localhost + gather_facts: False + tasks: + - name: Create Security group + ec2_group: + ec2_access_key: "{{ access_key }}" + ec2_secret_key: "{{ secret_key }}" + name: explorer-security + description: "Default security group" + region: "{{ region }}" +# purge_rules_egress: true +# purge_rules: true + rules: + - proto: tcp + from_port: 22 + to_port: 22 + cidr_ip: 0.0.0.0/0 + - proto: tcp + from_port: 443 + to_port: 443 + cidr_ip: 0.0.0.0/0 + - proto: tcp + from_port: 3000 + to_port: 3000 + cidr_ip: 0.0.0.0/0 + - proto: tcp + from_port: 30303 + to_port: 30303 + cidr_ip: 0.0.0.0/0 + - proto: udp + from_port: 30303 + to_port: 30303 + cidr_ip: 0.0.0.0/0 + rules_egress: + - proto: all + from_port: all + to_port: all + cidr_ip: 0.0.0.0/0 + tags: explorer + + +- name: Create explorer + hosts: localhost + gather_facts: False + vars: + volumes: + - device_name: /dev/sda1 + volume_size: 128 + delete_on_termination: true + tasks: + - name: Launch instance + ec2: + ec2_access_key: "{{ access_key }}" + ec2_secret_key: "{{ secret_key }}" + key_name: "{{ awskeypair_name }}" + instance_tags: + Name: "{{ explorer_instance_name }}" + group: "{{ explorer_security_group }}" + instance_type: "{{ explorer_instance_type }}" + image: "{{ image }}" + count: "{{ explorer_count_instances }}" + wait: yes + region: "{{ region }}" + vpc_subnet_id: "{{ vpc_subnet_id }}" + volumes: "{{ volumes }}" + assign_public_ip: yes + register: ec2 + - name: Add new instance to host group + add_host: hostname={{ item.public_ip }} groupname=launched + with_items: "{{ ec2.instances }}" + - name: Wait for SSH to come up + wait_for: host={{ item.public_ip }} port=22 delay=90 timeout=320 state=started + with_items: "{{ ec2.instances }}" + tags: explorer + +- name: Installing python + hosts: all + hosts: launched + gather_facts: False + user: ubuntu + become: True + vars: + ansible_ssh_port: 22 + tasks: + - name: Install python + raw: test -e /usr/bin/python || (sudo apt -y update && sudo apt install -y python-minimal) + +- name: Configure instance(s) + hosts: launched + user: ubuntu + become: True + vars: + ansible_ssh_port: 22 + gather_facts: True + roles: + - preconf + tags: preconf + tasks: + - name: restart machine after setup + shell: shutdown -r 1 diff --git a/group_vars/all.example b/group_vars/all.example index ae1d570..7aefa1f 100644 --- a/group_vars/all.example +++ b/group_vars/all.example @@ -69,3 +69,9 @@ owner_instance_type: "t2.large" owner_instance_name: "owner" owner_count_instances: "1" owner_security_group: "owner-security" + +#explorer +explorer_instance_type: "t2.large" +explorer_instance_name: "explorer" +explorer_count_instances: "1" +explorer_security_group: "explorer-security" diff --git a/hosts.example b/hosts.example index 2415fea..df6bb95 100644 --- a/hosts.example +++ b/hosts.example @@ -16,8 +16,11 @@ [mining] +[explorer] + [oracles:children] bootnode owner netstat mining +explorer diff --git a/netstat.yml b/netstat.yml index cfa90fb..6e955db 100644 --- a/netstat.yml +++ b/netstat.yml @@ -25,22 +25,6 @@ from_port: 3000 to_port: 3000 cidr_ip: 0.0.0.0/0 - - proto: tcp - from_port: 4000 - to_port: 4000 - cidr_ip: 0.0.0.0/0 - - proto: tcp - from_port: 8545 - to_port: 8545 - cidr_ip: 0.0.0.0/0 - - proto: tcp - from_port: 30303 - to_port: 30303 - cidr_ip: 0.0.0.0/0 - - proto: udp - from_port: 30303 - to_port: 30303 - cidr_ip: 0.0.0.0/0 rules_egress: - proto: all from_port: all diff --git a/roles/explorer/handlers/main.yml b/roles/explorer/handlers/main.yml new file mode 100644 index 0000000..c75c6af --- /dev/null +++ b/roles/explorer/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart oracles-chain-explorer + service: name=oracles-chain-explorer state=restarted diff --git a/roles/explorer/tasks/main.yml b/roles/explorer/tasks/main.yml new file mode 100644 index 0000000..fac3a82 --- /dev/null +++ b/roles/explorer/tasks/main.yml @@ -0,0 +1,78 @@ +--- +- name: Create directory parity_data/keys/OraclesPoA + file: + path: "{{ home }}/parity_data/keys/OraclesPoA" + state: directory + mode: 0700 + owner: "{{ username }}" + group: "{{ username }}" + +- name: Create logs directories + file: + path: "/{{ home }}/logs/old" + state: directory + mode: 0755 + owner: "{{ username }}" + group: "{{ username }}" + +- name: Download spec.json + get_url: url={{ item }} dest={{ home }}/ mode=0644 + with_items: + - "https://raw.githubusercontent.com/oraclesorg/oracles-scripts/sokol/spec.json" + - "https://raw.githubusercontent.com/oraclesorg/deployment-azure/dev-mainnet/nodes/bootnodes.txt" + - "https://raw.githubusercontent.com/oraclesorg/deployment-azure/dev-mainnet/nodes/netstats-server/node.toml" + + +- name: Change nat in node.toml + lineinfile: + path: "{{ home }}/node.toml" + insertafter: '^\[network\]' + line: nat="extip:{{ ansible_host }}" + state: present + +- name: Change reserved_peers in node.toml + lineinfile: + path: "{{ home }}/node.toml" + insertafter: '^\[network\]' + line: reserved_peers="{{ home }}/bootnodes.txt" + state: present + +- name: Add log file in node.toml + blockinfile: + path: "{{ home }}/node.toml" + block: | + [misc] + log_file = "{{ home }}/logs/parity.log" + +- git: repo=https://github.com/oraclesorg/oracles-dapps-keys-generation.git dest={{ home }}/parity_data/dapps/KeysGenerator +- git: repo=https://github.com/oraclesorg/oracles-dapps-voting.git dest={{ home }}/parity_data/dapps/Voting +- git: repo=https://github.com/oraclesorg/oracles-dapps-validators.git dest={{ home }}/parity_data/dapps/ValidatorsList + +- git: repo=https://github.com/oraclesorg/chain-explorer dest={{ home }}/chain-explorer + +- name: Install chain_explorer app.json + template: src=app.json.j2 dest={{ home }}/chain-explorer/app.json owner={{ username }} group={{ username }} mode=0644 + notify: + - restart oracles-chain-explorer + +- file: path={{ home }} owner={{ username }} group={{ username }} recurse=yes + +- name: install npm chain_explorer + shell: "cd /home/{{ username }}/chain-explorer; /usr/bin/npm install" + become: true + become_user: "{{ username }}" + notify: + - restart oracles-chain-explorer + +- name: Install chain_explorer config.js + template: src=config.js.j2 dest={{ home }}/chain-explorer/config.js owner={{ username }} group={{ username }} mode=0644 + notify: + - restart oracles-chain-explorer + +- name: Install oracles-chain-explorer service + template: src=oracles-chain-explorer.j2 dest=/etc/systemd/system/oracles-chain-explorer.service owner=root group=root mode=0755 + notify: + - restart oracles-chain-explorer + +- name: Ensure oracles-chain-explorer is running and enabled to start at boot + service: name=oracles-chain-explorer state=started enabled=yes diff --git a/roles/explorer/templates/app.json.j2 b/roles/explorer/templates/app.json.j2 new file mode 100644 index 0000000..b07d1b9 --- /dev/null +++ b/roles/explorer/templates/app.json.j2 @@ -0,0 +1,19 @@ +[ + { + "name" : "explorer", + "script" : "./bin/www", + "log_date_format" : "YYYY-MM-DD HH:mm:SS Z", + "error_file" : "/home/{{ username }}/logs/explorer.err", + "out_file" : "/home/{{ username }}/logs/explorer.out", + "merge_logs" : false, + "watch" : false, + "max_restarts" : 100, + "exec_interpreter" : "node", + "exec_mode" : "fork_mode", + "env": + { + "NODE_ENV" : "production", + "PORT" : 4000, + } + } +] diff --git a/roles/explorer/templates/config.js.j2 b/roles/explorer/templates/config.js.j2 new file mode 100644 index 0000000..3fe2445 --- /dev/null +++ b/roles/explorer/templates/config.js.j2 @@ -0,0 +1,12 @@ +var web3 = require('web3'); +var net = require('net'); +var config = function () { + this.logFormat = "combined"; + this.ipcPath = "/home/{{ username }}/parity_data/jsonrpc.ipc"; + this.provider = new web3.providers.IpcProvider(this.ipcPath, net); + this.bootstrapUrl = "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/yeti/bootstrap.min.css"; + this.names = { + "{{ OWNER_ADDRESS }}": "Owner", + }; +} +module.exports = config; diff --git a/roles/netstat/templates/oracles-chain-explorer.j2 b/roles/explorer/templates/oracles-chain-explorer.j2 similarity index 100% rename from roles/netstat/templates/oracles-chain-explorer.j2 rename to roles/explorer/templates/oracles-chain-explorer.j2 diff --git a/roles/netstat/handlers/main.yml b/roles/netstat/handlers/main.yml index 17187ac..b472616 100644 --- a/roles/netstat/handlers/main.yml +++ b/roles/netstat/handlers/main.yml @@ -1,6 +1,3 @@ --- -- name: restart oracles-chain-explorer - service: name=oracles-chain-explorer state=restarted - - name: restart oracles-dashboard service: name=oracles-dashboard state=restarted diff --git a/roles/netstat/tasks/main.yml b/roles/netstat/tasks/main.yml index 9b1fc43..1d25b27 100644 --- a/roles/netstat/tasks/main.yml +++ b/roles/netstat/tasks/main.yml @@ -49,10 +49,6 @@ - git: repo=https://github.com/oraclesorg/oracles-dapps-validators.git dest={{ home }}/parity_data/dapps/ValidatorsList - git: repo=https://github.com/oraclesorg/eth-netstats dest={{ home }}/eth-netstats -- git: repo=https://github.com/oraclesorg/chain-explorer dest={{ home }}/chain-explorer - -- name: Install chain_explorer app.json - template: src=app.json.j2 dest={{ home }}/chain-explorer/app.json owner={{ username }} group={{ username }} mode=0644 - file: path={{ home }} owner={{ username }} group={{ username }} recurse=yes @@ -76,18 +72,6 @@ notify: - restart oracles-dashboard -- name: install npm chain_explorer - shell: "cd /home/{{ username }}/chain-explorer; /usr/bin/npm install" - become: true - become_user: "{{ username }}" - notify: - - restart oracles-dashboard - -- name: Install chain_explorer config.js - template: src=config.js.j2 dest={{ home }}/chain-explorer/config.js owner={{ username }} group={{ username }} mode=0644 - notify: - - restart oracles-chain-explorer - - name: Install oracles-dashboard service template: src=oracles-dashboard.j2 dest=/etc/systemd/system/oracles-dashboard.service owner=root group=root mode=0755 notify: @@ -95,11 +79,3 @@ - name: Ensure oracles-dashboard is running and enabled to start at boot service: name=oracles-dashboard state=started enabled=yes - -- name: Install oracles-chain-explorer service - template: src=oracles-chain-explorer.j2 dest=/etc/systemd/system/oracles-chain-explorer.service owner=root group=root mode=0755 - notify: - - restart oracles-chain-explorer - -- name: Ensure oracles-chain-explorer is running and enabled to start at boot - service: name=oracles-chain-explorer state=started enabled=yes diff --git a/site.yml b/site.yml index 6b3e7ff..4c2c10b 100644 --- a/site.yml +++ b/site.yml @@ -65,6 +65,24 @@ tags: - netstat +- hosts: explorer + vars: + PROXY_PORT: "4000" + explorerS_SERVER: "localhost" + username: "explorer" + users: + - name: "explorer" + home: "/home/explorer" + roles: + - usermanager + - nodejs + - oracles-logrotate + - oracles-pm2 + - oracles-netstats + - explorer + tags: + - explorer + - hosts: owner vars: username: "owner"