very raw new templates for mining and netstat node, not for use.

This commit is contained in:
Vitaly Znachenok 2017-11-25 00:56:15 +03:00
parent 82b380c61a
commit a638126a5b
21 changed files with 660 additions and 14 deletions

View File

@ -1,5 +1,5 @@
---
- name: Create security group
- name: Create bootnode security group
hosts: localhost
gather_facts: False
tasks:
@ -7,7 +7,7 @@
ec2_group:
ec2_access_key: "{{ access_key }}"
ec2_secret_key: "{{ secret_key }}"
name: default-security
name: bootnode-security
description: "Default security group"
region: "{{ region }}"
# purge_rules_egress: true
@ -38,13 +38,13 @@
from_port: all
to_port: all
cidr_ip: 0.0.0.0/0
tags: bootnode
- name: Create a sandbox instance
- name: Create bootnode
hosts: localhost
gather_facts: False
vars:
security_group: ['default-security']
volumes:
- device_name: /dev/sda1
volume_size: 128
@ -57,7 +57,7 @@
key_name: "{{ awskeypair_name }}"
instance_tags:
Name: "{{ instance_name }}"
group: "{{ security_group }}"
group: "{{ bootnode_security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
count: "{{ count_instances }}"
@ -73,6 +73,7 @@
- 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: bootnode
- name: Installing python
hosts: all

View File

@ -16,13 +16,45 @@ access_key: "_INSERT KEY HERE_"
secret_key: "_INSERT SECRET HERE_"
awskeypair_name: "keypairname"
instance_type: "t2.large"
image: "ami-9d04e4e5"
region: "us-west-2"
instance_name: "bootnode"
count_instances: "1"
vpc_subnet_id: "subnet-ID-number"
NODE_FULLNAME: "_INSERT NODENAME_"
NODE_ADMIN_EMAIL: "_INSERT@EMAIL_"
NETSTATS_SERVER: "_INSERT SERVERNAME_"
NETSTATS_SECRET: "_INSERT SECRET_"
MINING_KEYFILE: "_INSERT_"
MINING_ADDRESS: "_INSERT_"
MINING_KEYPASS: "_INSERT_"
SCRIPTS_BRANCH: "sokol"
DAPPS_BRANCH: "master"
IKEYS_BRANCH: "master"
TX_GAS_LIMIT: "6700000"
NODE_PWD: "node.pwd"
parity_nouncles: "https://transfer.sh/PhhDc/parity"
#bootnode
bootnode_instance_type: "t2.large"
bootnode_instance_name: "bootnode"
bootnode_count_instances: "1"
bootnode_security_group: "bootnode-security"
#netstat
netstat_instance_type: "t2.large"
netstat_instance_name: "netstat"
netstat_count_instances: "1"
netstat_security_group: "netstat-security"
#mining
mining_instance_type: "t2.large"
mining_instance_name: "mining"
mining_count_instances: "1"
mining_security_group: "mining-security"

98
mining.yml Normal file
View File

@ -0,0 +1,98 @@
---
- name: Create mining 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: mining-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: 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
to_port: all
cidr_ip: 0.0.0.0/0
tags: mining
- name: Create mining
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: "{{ instance_name }}"
group: "{{ mining_security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
count: "{{ 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: mining
- 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

110
netstat.yml Normal file
View File

@ -0,0 +1,110 @@
---
- name: Create netstat 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: netstat-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: 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
to_port: all
cidr_ip: 0.0.0.0/0
tags: netstat
- name: Create netstat
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: "{{ instance_name }}"
group: "{{ netstat_security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
count: "{{ 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: netstat
- 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

View File

@ -87,13 +87,11 @@
shell: "cd /home/bootnode/eth-net-intelligence-api; /usr/bin/npm install"
become: true
become_user: "{{ username }}"
tags: test
- name: install npm oracles-initial-keys
shell: "cd /home/bootnode/oracles-initial-keys; /usr/bin/npm install"
become: true
become_user: "{{ username }}"
tags: test
- name: Install oracles-netstats service
template: src=oracles-netstats.j2 dest=/etc/systemd/system/oracles-netstats.service owner=root group=root mode=0755

106
roles/mining/tasks/main.yml Normal file
View File

@ -0,0 +1,106 @@
---
- 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/bootnode/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"
[account]
password = "{{ NODE_PWD }}"
unlock = "{{ MINING_ADDRESS }}"
[mining]
force_sealing = true
engine_signer = "{{ MINING_ADDRESS }}"
tx_gas_limit = "{{ TX_GAS_LIMIT }}"
reseal_on_txs = "none"
- name: Download parity-nouncles
get_url: url="{{ parity_nouncles }}" dest={{ home }}/parity-nouncles mode=0755
- name: Install oracles-parity service
template: src=oracles-parity.j2 dest=/etc/systemd/system/oracles-parity.service owner=root group=root mode=0755
- name: Ensure oracles-parity is running and enabled to start at boot
service: name=oracles-parity state=started enabled=yes
- name: Install oracles-pm2 service
template: src=oracles-pm2.j2 dest=/etc/systemd/system/oracles-pm2.service owner=root group=root mode=0755
- name: Install npm pm2
npm: name="pm2" global="yes"
- name: Ensure oracles-pm2 is running and enabled to start at boot
service: name=oracles-pm2 state=started enabled=yes
- git: repo=https://github.com/oraclesorg/eth-net-intelligence-api dest={{ home }}/eth-net-intelligence-api
- name: Install netstats config
template: src=app.json.j2 dest={{ home }}/eth-net-intelligence-api/app.json owner=bootnode group=bootnode mode=0644
- file: path={{ home }} owner={{ username }} group={{ username }} recurse=yes
- name: install npm netstats
shell: "cd /home/bootnode/eth-net-intelligence-api; /usr/bin/npm install"
become: true
become_user: "{{ username }}"
- name: Install oracles-netstats service
template: src=oracles-netstats.j2 dest=/etc/systemd/system/oracles-netstats.service owner=root group=root mode=0755
- name: Ensure oracles-netstats is running and enabled to start at boot
service: name=oracles-netstats state=started enabled=yes
- name: Install oracles-logrotate conf
template: src=oracles-logrotate.conf.j2 dest={{ home }}/oracles-logrotate.conf owner=root group=root mode=0644
- name: Install oracles-logrotate cron
template: src=oracles-logrotate.j2 dest=/etc/cron.hourly/oracles-logrotate owner=root group=root mode=0755
- git: repo=https://github.com/oraclesorg/oracles-scripts.git dest={{ home }}/oracles-scripts
- file: src="{{ home }}/node.toml" dest="{{ home }}/oracles-scripts/node.toml" owner="{{ username }}" group="{{ username }}" state=link
- name: install npm scripts
shell: "cd {{ home }}/oracles-scripts/; /usr/bin/npm install"
become: true
become_user: "{{ username }}"
- name: Install Payout task.
template: src=transferRewardToPayoutKey.j2 dest=/etc/cron.hourly/transferRewardToPayoutKey owner=root group=root mode=0755

View File

@ -0,0 +1,26 @@
[
{
"name" : "netstats_daemon",
"script" : "app.js",
"log_date_format" : "YYYY-MM-DD HH:mm:SS Z",
"error_file" : "/home/{{ username }}/logs/netstats_daemon.err",
"out_file" : "/home/{{ username }}/logs/netstats_daemon.out",
"merge_logs" : false,
"watch" : false,
"max_restarts" : 100,
"exec_interpreter" : "node",
"exec_mode" : "fork_mode",
"env":
{
"NODE_ENV" : "production",
"RPC_HOST" : "localhost",
"RPC_PORT" : "8545",
"LISTENING_PORT" : "30300",
"INSTANCE_NAME" : "{{ NODE_FULLNAME }}",
"CONTACT_DETAILS" : "{{ NODE_ADMIN_EMAIL }}",
"WS_SERVER" : "http://{{ NETSTATS_SERVER }}:3000",
"WS_SECRET" : "{{ NETSTATS_SECRET }}",
"VERBOSITY" : 2
}
}
]

View File

@ -0,0 +1,20 @@
/home/{{ username }}/logs/*.log {
rotate 10
size 200M
missingok
compress
copytruncate
dateext
dateformat %Y-%m-%d-%s
olddir old
}
/home/{{ username }}/.pm2/pm2.log {
su {{ username }} {{ username }}
rotate 10
size 200M
missingok
compress
copytruncate
dateext
dateformat %Y-%m-%d-%s
}

View File

@ -0,0 +1,2 @@
#!/bin/bash
/usr/sbin/logrotate /home/{{ username }}/oracles-logrotate.conf

View File

@ -0,0 +1,13 @@
[Unit]
Description=oracles netstats service
After=oracles-pm2.service
[Service]
Type=oneshot
RemainAfterExit=true
User={{ username }}
Group={{ username }}
Environment=MYVAR=myval
WorkingDirectory=/home/{{ username }}/eth-net-intelligence-api
ExecStart=/usr/bin/pm2 startOrRestart app.json
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,11 @@
[Unit]
Description=oracles parity service
After=network.target
[Service]
User={{ username }}
Group={{ username }}
WorkingDirectory=/home/{{ username }}
ExecStart=/home/{{ username }}/parity-nouncles --config=node.toml
Restart=always
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,13 @@
[Unit]
Description=oracles pm2 service
After=network.target
[Service]
Type=oneshot
RemainAfterExit=true
User={{ username }}
Group={{ username }}
Environment=MYVAR=myval
WorkingDirectory=/home/{{ username }}
ExecStart=/usr/bin/pm2 ping
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,7 @@
#!/bin/bash
cd "{{ home }}/oracles-scripts/scripts/"
echo \"Starting at \\\$(date)\" >> \"/home/{{ username }}/logs/transferRewardToPayoutKey.out\"
echo \"Starting at \\\$(date)\" >> \"/home/{{ username }}/logs/transferRewardToPayoutKey.err\"
node {{ home }}/oracles-scripts/scripts/transferRewardToPayoutKey.js >> \"/home/{{ username }}/logs/transferRewardToPayoutKey.out\" 2>> \"/home/${{ username }}/logs/transferRewardToPayoutKey.err\"
echo \"\" >> \"/home/{{ username }}/logs/transferRewardToPayoutKey.out\"
echo \"\" >> \"/home/{{ username }}/logs/transferRewardToPayoutKey.err\"

View File

@ -0,0 +1,109 @@
---
- name: Create directory parity_data/keys/OraclesPoA
file:
path: "{{ home }}/parity_data/keys/OraclesPoA"
state: directory
mode: 0700
owner: "{{ username }}"
group: "{{ username }}"
- name: Create directory parity_data/dapps
file:
path: "{{ home }}/parity_data/dapps"
state: directory
mode: 0755
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/test-templates/dev-mainnet/TestTestNet/bootnodes.txt"
- "https://raw.githubusercontent.com/oraclesorg/test-templates/dev-mainnet/TestTestNet/bootnode/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
- name: Download parity-nouncles
get_url: url="{{ parity_nouncles }}" dest={{ home }}/parity-nouncles mode=0755
- name: Install oracles-parity service
template: src=oracles-parity.j2 dest=/etc/systemd/system/oracles-parity.service owner=root group=root mode=0755
- name: Ensure oracles-parity is running and enabled to start at boot
service: name=oracles-parity state=started enabled=yes
- name: Install oracles-pm2 service
template: src=oracles-pm2.j2 dest=/etc/systemd/system/oracles-pm2.service owner=root group=root mode=0755
- name: Install npm pm2
npm: name="pm2" global="yes"
- name: Ensure oracles-pm2 is running and enabled to start at boot
service: name=oracles-pm2 state=started enabled=yes
- git: repo=https://github.com/oraclesorg/eth-net-intelligence-api dest={{ home }}/eth-net-intelligence-api
- name: Install netstats config
template: src=app.json.j2 dest={{ home }}/eth-net-intelligence-api/app.json owner=bootnode group=bootnode mode=0644
- git: repo=https://github.com/oraclesorg/oracles-initial-keys dest={{ home }}/oracles-initial-keys
- file: path={{ home }} owner={{ username }} group={{ username }} recurse=yes
- name: install npm netstats
shell: "cd /home/bootnode/eth-net-intelligence-api; /usr/bin/npm install"
become: true
become_user: "{{ username }}"
tags: test
- name: install npm oracles-initial-keys
shell: "cd /home/bootnode/oracles-initial-keys; /usr/bin/npm install"
become: true
become_user: "{{ username }}"
tags: test
- name: Install oracles-netstats service
template: src=oracles-netstats.j2 dest=/etc/systemd/system/oracles-netstats.service owner=root group=root mode=0755
- name: Ensure oracles-netstats is running and enabled to start at boot
service: name=oracles-netstats state=started enabled=yes
- name: Install oracles-logrotate conf
template: src=oracles-logrotate.conf.j2 dest={{ home }}/oracles-logrotate.conf owner=root group=root mode=0644
- name: Install oracles-logrotate cron
template: src=oracles-logrotate.j2 dest=/etc/cron.hourly/oracles-logrotate owner=root group=root mode=0755

View File

@ -0,0 +1,26 @@
[
{
"name" : "netstats_daemon",
"script" : "app.js",
"log_date_format" : "YYYY-MM-DD HH:mm:SS Z",
"error_file" : "/home/{{ username }}/logs/netstats_daemon.err",
"out_file" : "/home/{{ username }}/logs/netstats_daemon.out",
"merge_logs" : false,
"watch" : false,
"max_restarts" : 100,
"exec_interpreter" : "node",
"exec_mode" : "fork_mode",
"env":
{
"NODE_ENV" : "production",
"RPC_HOST" : "localhost",
"RPC_PORT" : "8545",
"LISTENING_PORT" : "30300",
"INSTANCE_NAME" : "{{ NODE_FULLNAME }}",
"CONTACT_DETAILS" : "{{ NODE_ADMIN_EMAIL }}",
"WS_SERVER" : "http://{{ NETSTATS_SERVER }}:3000",
"WS_SECRET" : "{{ NETSTATS_SECRET }}",
"VERBOSITY" : 2
}
}
]

View File

@ -0,0 +1,20 @@
/home/{{ username }}/logs/*.log {
rotate 10
size 200M
missingok
compress
copytruncate
dateext
dateformat %Y-%m-%d-%s
olddir old
}
/home/{{ username }}/.pm2/pm2.log {
su {{ username }} {{ username }}
rotate 10
size 200M
missingok
compress
copytruncate
dateext
dateformat %Y-%m-%d-%s
}

View File

@ -0,0 +1,2 @@
#!/bin/bash
/usr/sbin/logrotate /home/{{ username }}/oracles-logrotate.conf

View File

@ -0,0 +1,13 @@
[Unit]
Description=oracles netstats service
After=oracles-pm2.service
[Service]
Type=oneshot
RemainAfterExit=true
User={{ username }}
Group={{ username }}
Environment=MYVAR=myval
WorkingDirectory=/home/{{ username }}/eth-net-intelligence-api
ExecStart=/usr/bin/pm2 startOrRestart app.json
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,11 @@
[Unit]
Description=oracles parity service
After=network.target
[Service]
User={{ username }}
Group={{ username }}
WorkingDirectory=/home/{{ username }}
ExecStart=/home/{{ username }}/parity-nouncles --config=node.toml
Restart=always
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,13 @@
[Unit]
Description=oracles pm2 service
After=network.target
[Service]
Type=oneshot
RemainAfterExit=true
User={{ username }}
Group={{ username }}
Environment=MYVAR=myval
WorkingDirectory=/home/{{ username }}
ExecStart=/usr/bin/pm2 ping
[Install]
WantedBy=multi-user.target

View File

@ -20,14 +20,29 @@
users:
- name: "bootnode"
home: "/home/bootnode"
parity_nouncles: "https://transfer.sh/PhhDc/parity"
logsprefix: "/home/bootnode/logs"
logentries_user_key: "0665901a-e843-41c5-82c1-2cc4b39f0b21"
# logsprefix: "/home/bootnode/logs"
# logentries_user_key: "0665901a-e843-41c5-82c1-2cc4b39f0b21"
roles:
- usermanager
- logentries
# - logentries
- nodejs
- bootnode
- nginx
tags:
- bootnode
- hosts: mining
vars:
username: "mining"
users:
- name: "mining"
home: "/home/mining"
# logsprefix: "/home/mining/logs"
# logentries_user_key: "0665901a-e843-41c5-82c1-2cc4b39f0b21"
roles:
- usermanager
# - logentries
- nodejs
- mining
tags:
- mining