From 99d88215acb2becac5a903fac46df5f31114eab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Mon, 22 Mar 2021 15:01:58 +0100 Subject: [PATCH 01/16] Add first steps for a non docker ansible deploy --- ansible/README.md | 2 +- ansible/deploy_regular_node.yml | 120 ++++++++++++++++++------- ansible/deploy_regular_node_docker.yml | 40 +++++++++ ansible/group_vars/regular_nodes | 12 ++- 4 files changed, 141 insertions(+), 33 deletions(-) create mode 100644 ansible/deploy_regular_node_docker.yml diff --git a/ansible/README.md b/ansible/README.md index f112070..9dd7493 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -37,7 +37,7 @@ Once you have the variables set, you can... Execute the command from your local machine: ```bash -ansible-playbook -i host deploy_regular_node.yml -vv +ansible-playbook -i host deploy_regular_node_docker.yml -vv ``` This will install Docker and run the docker container inside with the variables you set when you run the diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index 2e9e49c..fe072fc 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -1,40 +1,98 @@ --- - hosts: all - remote_user: ubuntu + remote_user: '{{ remote_user }}' + environment: + PATH: /usr/local/go/bin:{{ ansible_env.PATH }} tasks: - - name: Install docker + - name: Add the deploy user become: yes - apt: - name: docker.io + user: + name: '{{ deploy_user }}' state: present + + - name: Install dependencies + become: yes + package: + name: + - git + - curl + - dnsutils + - net-tools + - logrotate + - software-properties-common + - unzip + - wget + - make + - gcc + - libsodium-dev + - build-essential + - libdb-dev + - zlib1g-dev + - libtinfo-dev + - sysvbanner + - psmisc + - libleveldb-dev + - libsodium-dev + - libdb5.3-dev + - dnsutils + state: latest - - name: 'add users to docker group' + - name: Install Golang compiler become: yes - user: - name: '{{ deploy_user }}' - groups: 'docker' - append: 'yes' - - - name: Clone and update the repo - git: - repo: '{{ project_repo }}' - dest: '{{ project_path }}' - version: '{{ project_repo_version }}' - force: yes - accept_hostkey: yes - - - name: Execute init.sh to create the regular node - shell: ./init.sh - args: - chdir: '{{ project_path }}/docker/general' - environment: - COMPANY_NAME: '{{ company_name }}' - CPU: '{{ cpu_number }}' - RAM: '{{ ram_number }}' - SEQ: '{{ sequential }}' - ENABLE_CONSTELLATION: '{{ enable_constellation }}' - MONITOR_ENABLED: '{{ enable_monitor }}' - NO_LAUNCH_CONFIRM: '{{ no_launch_confirm }}' - EXTRA_DOCKER_ARGUMENTS: '{{ extra_docker_arguments }}' + unarchive: + src: https://storage.googleapis.com/golang/'{{ golang_version }}' + dest: /usr/local/ + remote_src: yes + + - name: Install Quorum + become: yes + block: + - name: Clone Quorum repository + git: + repo: https://github.com/ConsenSys/quorum.git + dest: /tmp/quorum + version: '{{ quorum_version }}' + - name: Execute make command + shell: make -C /tmp/quorum all + - name: Copy geth to right location + copy: + src: /tmp/quorum/build/bin/geth + dest: /usr/local/bin/geth + - name: Copy bootnode to right location + copy: + src: /tmp/quorum/build/bin/bootnode + dest: /usr/local/bin/bootnode + + - name: Check that the INITIALIZED file exists + stat: + path: ~/data/INITIALIZED + register: INITIALIZED + + - name: Initialize the node if necessary + become: yes + become_user: '{{ deploy_user }}' + when: not INITIALIZED.stat.exists + block: + - name: Create the data directory if it does not exist yet + file: + path: ~/data + state: directory + + - name: Create the nodekey + shell: /usr/local/bin/bootnode -genkey ~/data/nodekey + + - name: Get the enode key + shell: /usr/local/bin/bootnode -nodekey ~/data/nodekey -writeaddress > ~/data/ENODE_ADDRESS + + - name: Download genesis.json + get_url: + url: '{{ genesis_json_url }}' + dest: ~/genesis.json + + - name: Execute geth command + shell: /usr/local/bin/geth --datadir ~/data init ~/genesis.json + + - name: Mark the node as initialized + shell: /bin/echo "INITIALIZED" > ~/data/INITIALIZED diff --git a/ansible/deploy_regular_node_docker.yml b/ansible/deploy_regular_node_docker.yml new file mode 100644 index 0000000..3b9836e --- /dev/null +++ b/ansible/deploy_regular_node_docker.yml @@ -0,0 +1,40 @@ +--- + +- hosts: all + remote_user: '{{ remote_user }}' + + tasks: + - name: Install docker + become: yes + apt: + name: docker.io + state: present + + - name: 'add users to docker group' + become: yes + user: + name: '{{ deploy_user }}' + groups: 'docker' + append: 'yes' + + - name: Clone and update the repo + git: + repo: '{{ project_repo }}' + dest: '{{ project_path }}' + version: '{{ project_repo_version }}' + force: yes + accept_hostkey: yes + + - name: Execute init.sh to create the regular node + shell: ./init.sh + args: + chdir: '{{ project_path }}/docker/general' + environment: + COMPANY_NAME: '{{ company_name }}' + CPU: '{{ cpu_number }}' + RAM: '{{ ram_number }}' + SEQ: '{{ sequential }}' + ENABLE_CONSTELLATION: '{{ enable_constellation }}' + MONITOR_ENABLED: '{{ enable_monitor }}' + NO_LAUNCH_CONFIRM: '{{ no_launch_confirm }}' + EXTRA_DOCKER_ARGUMENTS: '{{ extra_docker_arguments }}' diff --git a/ansible/group_vars/regular_nodes b/ansible/group_vars/regular_nodes index 7baf295..13e8b91 100644 --- a/ansible/group_vars/regular_nodes +++ b/ansible/group_vars/regular_nodes @@ -2,7 +2,11 @@ # You can change all these variables to your needs -deploy_user: ubuntu # SSH user connecting to the server +remote_user: ubuntu # SSH user connecting to the server +deploy_user: ubuntu # User who run the service + +# Variables for deploy_regular_node_docker + project_path: /home/{{ deploy_user }}/alastria-node project_repo: https://github.com/alastria-node/alastria-node project_repo_version: testnet2 @@ -15,3 +19,9 @@ enable_constellation: enable_monitor: no_launch_confirm: extra_docker_arguments: + +# Variables for deploy_regular_node + +genesis_json_url: https://raw.githubusercontent.com/alastria/alastria-node/testnet2/data/genesis.json +golang_version: go1.9.5.linux-amd64.tar.gz +quorum_version: v2.2.3 From 5bef7a5e1567cfb0d1662d4ce64da7e4e22bd290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Fri, 26 Mar 2021 13:06:30 +0100 Subject: [PATCH 02/16] Update README.md --- ansible/README.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ansible/README.md b/ansible/README.md index 9dd7493..74c6c23 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -4,8 +4,8 @@ You need to have installed [Ansible](https://www.ansible.com/) in your local machine. -The Docker installation and configuration may change if you're using other Operating System -to deploy, let me know if you have problems. +The installation can be donde using Docker or not. The Docker installation and configuration may +change if you're using other Operating System to deploy, let me know if you have problems. ### Configuration @@ -28,12 +28,15 @@ so you need to set it to `/usr/bin/python3`. ### Set your node variables These are the same variables you need to usually set when you create a node manually, but in this case Ansible -will do it for you, you can set them on the `group_vars/regular_nodes` path. +will do it for you, you can set them on the `group_vars/regular_nodes` path. Depending on whether you use Docker +or prefer a native installation you will need to set differents groups of variables. Once you have the variables set, you can... ## Run the node +### Docker + Execute the command from your local machine: ```bash @@ -42,3 +45,14 @@ ansible-playbook -i host deploy_regular_node_docker.yml -vv This will install Docker and run the docker container inside with the variables you set when you run the command. + +### Native + +Execute the command from your local machine: + +```bash +ansible-playbook -i host deploy_regular_node.yml -vv +``` + +This will install everything natively and start the quorum node with the variables you set when you run the +command. From 7db7880e45cc6355391ece4357a7acf52cac4966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Fri, 26 Mar 2021 13:43:07 +0100 Subject: [PATCH 03/16] Start adding commands to get eth nodes --- ansible/deploy_regular_node.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index fe072fc..ca2178d 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -96,3 +96,17 @@ - name: Mark the node as initialized shell: /bin/echo "INITIALIZED" > ~/data/INITIALIZED + + - name: 'Get nodes and start geth node' + become: yes + become_user: '{{ deploy_user }}' + block: + - name: Create temporary file + tempfile: + path: /tmp/updatePerm.XXXXXX + register: TMPFILE + - name: Create the data directory if it does not exist yet + shell: | + for i in boot-nodes.json validator-nodes.json regular-nodes.json ; do + wget -q -O ~/env/${i} https://raw.githubusercontent.com/alastria/alastria-node/${NODE_BRANCH}/data/${i} + done From d093694931f278a763392d26eb085e9d0f04f6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Tue, 13 Apr 2021 16:36:46 +0200 Subject: [PATCH 04/16] Finish ansible for non docker version --- ansible/deploy_regular_node.yml | 49 +++++++++++++++++++++++++------- ansible/group_vars/regular_nodes | 2 ++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index ca2178d..8622013 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -1,15 +1,15 @@ --- - hosts: all - remote_user: '{{ remote_user }}' + remote_user: {{ remote_user|quote }} environment: - PATH: /usr/local/go/bin:{{ ansible_env.PATH }} + PATH: /usr/local/go/bin:{{ ansible_env.PATH|quote }} tasks: - name: Add the deploy user become: yes user: - name: '{{ deploy_user }}' + name: {{ deploy_user|quote }} state: present - name: Install dependencies @@ -42,7 +42,7 @@ - name: Install Golang compiler become: yes unarchive: - src: https://storage.googleapis.com/golang/'{{ golang_version }}' + src: https://storage.googleapis.com/golang/{{ golang_version|quote }} dest: /usr/local/ remote_src: yes @@ -53,7 +53,7 @@ git: repo: https://github.com/ConsenSys/quorum.git dest: /tmp/quorum - version: '{{ quorum_version }}' + version: {{ quorum_version|quote }} - name: Execute make command shell: make -C /tmp/quorum all - name: Copy geth to right location @@ -72,7 +72,7 @@ - name: Initialize the node if necessary become: yes - become_user: '{{ deploy_user }}' + become_user: {{ deploy_user|quote }} when: not INITIALIZED.stat.exists block: - name: Create the data directory if it does not exist yet @@ -88,7 +88,7 @@ - name: Download genesis.json get_url: - url: '{{ genesis_json_url }}' + url: {{ genesis_json_url|quote }} dest: ~/genesis.json - name: Execute geth command @@ -99,14 +99,43 @@ - name: 'Get nodes and start geth node' become: yes - become_user: '{{ deploy_user }}' + become_user: {{ deploy_user|quote }} block: - name: Create temporary file tempfile: path: /tmp/updatePerm.XXXXXX register: TMPFILE - - name: Create the data directory if it does not exist yet + - name: Get current nodes and parse databases shell: | for i in boot-nodes.json validator-nodes.json regular-nodes.json ; do - wget -q -O ~/env/${i} https://raw.githubusercontent.com/alastria/alastria-node/${NODE_BRANCH}/data/${i} + wget -q -O ~/env/${i} https://raw.githubusercontent.com/alastria/alastria-node/{{ node_branch|quote }}/data/${i} done + + case {{ node_type|quote }} in + "bootnode") + cat ~/env/boot-nodes.json ~/env/validator-nodes.json ~/env/regular-nodes.json >> {{ TMPFILE.path|quote }} + ;; + "validator") + cat ~/env/boot-nodes.json ~/env/validator-nodes.json >> {{ TMPFILE.path|quote }} + ;; + "general") + cat ~/env/boot-nodes.json >> {{ TMPFILE.path|quote }} + ;; + *) + echo "ERROR: nodetype not recognized" + exit 1 + ;; + esac + + sed -e '1s/^/[\n/' -i {{ TMPFILE.path|quote }} + sed -e '$s/,$/\n]/' -i {{ TMPFILE.path|quote }} + + cat {{ TMPFILE.path|quote }} > ~/data/static-nodes.json + cat {{ TMPFILE.path|quote }} > ~/data/permissioned-nodes.json + - name: Prepare geth and launch node + shell: | + source ~/env/geth.common.sh + source ~/env/geth.node.{{ node_type|quote }}.sh + + export PRIVATE_CONFIG="ignore" + exec /usr/local/bin/geth --datadir ~/data ${GLOBAL_ARGS} ${NETSTATS_METRICS} ${INFLUX_METRICS} ${NODE_ARGS} ${LOCAL_ARGS} diff --git a/ansible/group_vars/regular_nodes b/ansible/group_vars/regular_nodes index 13e8b91..24e5145 100644 --- a/ansible/group_vars/regular_nodes +++ b/ansible/group_vars/regular_nodes @@ -25,3 +25,5 @@ extra_docker_arguments: genesis_json_url: https://raw.githubusercontent.com/alastria/alastria-node/testnet2/data/genesis.json golang_version: go1.9.5.linux-amd64.tar.gz quorum_version: v2.2.3 +node_branch: main +node_type=general From 5c678a793879dc2326b6ba686cac3113e01bc62c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Tue, 13 Apr 2021 17:29:09 +0200 Subject: [PATCH 05/16] Fix yaml syntax --- ansible/deploy_regular_node.yml | 18 +++++++++--------- ansible/host | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index 8622013..f1eb8c1 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -1,7 +1,7 @@ --- - hosts: all - remote_user: {{ remote_user|quote }} + remote_user: "{{ remote_user|quote }}" environment: PATH: /usr/local/go/bin:{{ ansible_env.PATH|quote }} @@ -9,7 +9,7 @@ - name: Add the deploy user become: yes user: - name: {{ deploy_user|quote }} + name: "{{ deploy_user|quote }}" state: present - name: Install dependencies @@ -53,7 +53,7 @@ git: repo: https://github.com/ConsenSys/quorum.git dest: /tmp/quorum - version: {{ quorum_version|quote }} + version: "{{ quorum_version|quote }}" - name: Execute make command shell: make -C /tmp/quorum all - name: Copy geth to right location @@ -66,13 +66,13 @@ dest: /usr/local/bin/bootnode - name: Check that the INITIALIZED file exists - stat: - path: ~/data/INITIALIZED - register: INITIALIZED + stat: + path: ~/data/INITIALIZED + register: INITIALIZED - name: Initialize the node if necessary become: yes - become_user: {{ deploy_user|quote }} + become_user: "{{ deploy_user|quote }}" when: not INITIALIZED.stat.exists block: - name: Create the data directory if it does not exist yet @@ -88,7 +88,7 @@ - name: Download genesis.json get_url: - url: {{ genesis_json_url|quote }} + url: "{{ genesis_json_url|quote }}" dest: ~/genesis.json - name: Execute geth command @@ -99,7 +99,7 @@ - name: 'Get nodes and start geth node' become: yes - become_user: {{ deploy_user|quote }} + become_user: "{{ deploy_user|quote }}" block: - name: Create temporary file tempfile: diff --git a/ansible/host b/ansible/host index 91e47f7..353faa2 100644 --- a/ansible/host +++ b/ansible/host @@ -2,4 +2,4 @@ ansible_ssh_private_key_file= [regular_nodes] -: +127.0.0.1:22 From 0e7d3c7083f3cbb4bb618b78bdba78daf2d9e7e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Tue, 13 Apr 2021 17:49:42 +0200 Subject: [PATCH 06/16] Fix some values --- ansible/group_vars/regular_nodes | 2 +- ansible/host | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible/group_vars/regular_nodes b/ansible/group_vars/regular_nodes index 24e5145..f784e64 100644 --- a/ansible/group_vars/regular_nodes +++ b/ansible/group_vars/regular_nodes @@ -26,4 +26,4 @@ genesis_json_url: https://raw.githubusercontent.com/alastria/alastria-node/testn golang_version: go1.9.5.linux-amd64.tar.gz quorum_version: v2.2.3 node_branch: main -node_type=general +node_type: general diff --git a/ansible/host b/ansible/host index 353faa2..91e47f7 100644 --- a/ansible/host +++ b/ansible/host @@ -2,4 +2,4 @@ ansible_ssh_private_key_file= [regular_nodes] -127.0.0.1:22 +: From 82e89fd5bc418b998ba95fb9afb453c8e03d8d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Tue, 13 Apr 2021 18:20:29 +0200 Subject: [PATCH 07/16] Specify that the src files when copying are present in the remote --- ansible/deploy_regular_node.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index f1eb8c1..effc1dc 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -58,10 +58,12 @@ shell: make -C /tmp/quorum all - name: Copy geth to right location copy: + remote_src: yes src: /tmp/quorum/build/bin/geth dest: /usr/local/bin/geth - name: Copy bootnode to right location copy: + remote_src: yes src: /tmp/quorum/build/bin/bootnode dest: /usr/local/bin/bootnode From b11f65360bdc9c74e1818e021113ca0b9012feff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Tue, 13 Apr 2021 18:39:22 +0200 Subject: [PATCH 08/16] Fix some file permissions --- ansible/deploy_regular_node.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index effc1dc..1a762fd 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -16,6 +16,7 @@ become: yes package: name: + - sudo - git - curl - dnsutils @@ -61,11 +62,13 @@ remote_src: yes src: /tmp/quorum/build/bin/geth dest: /usr/local/bin/geth + mode: a+x - name: Copy bootnode to right location copy: remote_src: yes src: /tmp/quorum/build/bin/bootnode dest: /usr/local/bin/bootnode + mode: a+x - name: Check that the INITIALIZED file exists stat: @@ -105,7 +108,7 @@ block: - name: Create temporary file tempfile: - path: /tmp/updatePerm.XXXXXX + path: /tmp register: TMPFILE - name: Get current nodes and parse databases shell: | @@ -140,4 +143,4 @@ source ~/env/geth.node.{{ node_type|quote }}.sh export PRIVATE_CONFIG="ignore" - exec /usr/local/bin/geth --datadir ~/data ${GLOBAL_ARGS} ${NETSTATS_METRICS} ${INFLUX_METRICS} ${NODE_ARGS} ${LOCAL_ARGS} + exec /usr/local/bin/geth --datadir ~/data ${GLOBAL_ARGS} ${NETSTATS_METRICS} ${INFLUX_METRICS} ${NODE_ARGS} ${LOCAL_ARGS} & From 23ad2158af6f05442e6f7dbbf315df2f6c3bf4f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Tue, 13 Apr 2021 19:28:18 +0200 Subject: [PATCH 09/16] Add some necessary tasks and improve readability --- ansible/deploy_regular_node.yml | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index 1a762fd..3e0e5da 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -55,7 +55,7 @@ repo: https://github.com/ConsenSys/quorum.git dest: /tmp/quorum version: "{{ quorum_version|quote }}" - - name: Execute make command + - name: Compile geth shell: make -C /tmp/quorum all - name: Copy geth to right location copy: @@ -96,13 +96,13 @@ url: "{{ genesis_json_url|quote }}" dest: ~/genesis.json - - name: Execute geth command + - name: Execute geth init command shell: /usr/local/bin/geth --datadir ~/data init ~/genesis.json - name: Mark the node as initialized shell: /bin/echo "INITIALIZED" > ~/data/INITIALIZED - - name: 'Get nodes and start geth node' + - name: Get nodes and start geth node become: yes become_user: "{{ deploy_user|quote }}" block: @@ -110,6 +110,11 @@ tempfile: path: /tmp register: TMPFILE + - name: Create env directory + file: + path: ~/env + state: directory + mode: 0755 - name: Get current nodes and parse databases shell: | for i in boot-nodes.json validator-nodes.json regular-nodes.json ; do @@ -137,10 +142,15 @@ cat {{ TMPFILE.path|quote }} > ~/data/static-nodes.json cat {{ TMPFILE.path|quote }} > ~/data/permissioned-nodes.json + - name: Get initialization scripts + shell: | + for i in geth.common.sh geth.node.{{ node_type|quote }}.sh ; do + wget -q -O ~/env/${i} https://raw.githubusercontent.com/alejandroalffer/alastria-node-t/master/alastria-node-data/env/${i} + done - name: Prepare geth and launch node shell: | source ~/env/geth.common.sh source ~/env/geth.node.{{ node_type|quote }}.sh export PRIVATE_CONFIG="ignore" - exec /usr/local/bin/geth --datadir ~/data ${GLOBAL_ARGS} ${NETSTATS_METRICS} ${INFLUX_METRICS} ${NODE_ARGS} ${LOCAL_ARGS} & + nohup /usr/local/bin/geth --datadir ~/data ${GLOBAL_ARGS} ${NETSTATS_METRICS} ${INFLUX_METRICS} ${NODE_ARGS} ${LOCAL_ARGS} & From bda3959a04f004c38b5017dc846c19f9883d6115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Wed, 14 Apr 2021 10:08:42 +0200 Subject: [PATCH 10/16] Add some improvements --- ansible/deploy_regular_node.yml | 6 ++++-- ansible/group_vars/regular_nodes | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index 3e0e5da..1b2b9c3 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -93,7 +93,7 @@ - name: Download genesis.json get_url: - url: "{{ genesis_json_url|quote }}" + url: "https://raw.githubusercontent.com/alastria/alastria-node/{{ node_branch|quote }}/data/genesis.json" dest: ~/genesis.json - name: Execute geth init command @@ -152,5 +152,7 @@ source ~/env/geth.common.sh source ~/env/geth.node.{{ node_type|quote }}.sh - export PRIVATE_CONFIG="ignore" nohup /usr/local/bin/geth --datadir ~/data ${GLOBAL_ARGS} ${NETSTATS_METRICS} ${INFLUX_METRICS} ${NODE_ARGS} ${LOCAL_ARGS} & + environment: + PRIVATE_CONFIG: ignore + NODE_NAME: "REG_{{ company_name|quote }}_T_{{ cpu_number|quote }}_{{ ram_number|quote }}_{{ sequential|quote }}" diff --git a/ansible/group_vars/regular_nodes b/ansible/group_vars/regular_nodes index f784e64..0b4aabb 100644 --- a/ansible/group_vars/regular_nodes +++ b/ansible/group_vars/regular_nodes @@ -2,8 +2,14 @@ # You can change all these variables to your needs +# Variables for deploy_regular_node_docker and deploy_regular_node + remote_user: ubuntu # SSH user connecting to the server deploy_user: ubuntu # User who run the service +company_name: +cpu_number: +ram_number: +sequential: # Variables for deploy_regular_node_docker @@ -11,10 +17,6 @@ project_path: /home/{{ deploy_user }}/alastria-node project_repo: https://github.com/alastria-node/alastria-node project_repo_version: testnet2 -company_name: -cpu_number: -ram_number: -sequential: enable_constellation: enable_monitor: no_launch_confirm: @@ -22,8 +24,7 @@ extra_docker_arguments: # Variables for deploy_regular_node -genesis_json_url: https://raw.githubusercontent.com/alastria/alastria-node/testnet2/data/genesis.json golang_version: go1.9.5.linux-amd64.tar.gz quorum_version: v2.2.3 -node_branch: main +node_branch: testnet2 node_type: general From ea8d4edf75952a6e09aca33057ed3e60ea067716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Wed, 14 Apr 2021 10:42:36 +0200 Subject: [PATCH 11/16] Fix some envars --- ansible/group_vars/regular_nodes | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ansible/group_vars/regular_nodes b/ansible/group_vars/regular_nodes index 0b4aabb..444f2d4 100644 --- a/ansible/group_vars/regular_nodes +++ b/ansible/group_vars/regular_nodes @@ -4,7 +4,7 @@ # Variables for deploy_regular_node_docker and deploy_regular_node -remote_user: ubuntu # SSH user connecting to the server +remote_user: # SSH user connecting to the server deploy_user: ubuntu # User who run the service company_name: cpu_number: @@ -14,8 +14,8 @@ sequential: # Variables for deploy_regular_node_docker project_path: /home/{{ deploy_user }}/alastria-node -project_repo: https://github.com/alastria-node/alastria-node -project_repo_version: testnet2 +project_repo: https://github.com/alastria/alastria-node +project_repo_version: main enable_constellation: enable_monitor: @@ -26,5 +26,5 @@ extra_docker_arguments: golang_version: go1.9.5.linux-amd64.tar.gz quorum_version: v2.2.3 -node_branch: testnet2 +node_branch: main node_type: general From 14eac8d0b36f2e765d1e07c91d463d5b63885343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Wed, 14 Apr 2021 12:11:07 +0200 Subject: [PATCH 12/16] Change shell type when necessary and use screen to keep geth running --- ansible/deploy_regular_node.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index 1b2b9c3..896d54f 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -38,6 +38,7 @@ - libsodium-dev - libdb5.3-dev - dnsutils + - screen state: latest - name: Install Golang compiler @@ -142,17 +143,23 @@ cat {{ TMPFILE.path|quote }} > ~/data/static-nodes.json cat {{ TMPFILE.path|quote }} > ~/data/permissioned-nodes.json + args: + executable: /bin/bash - name: Get initialization scripts shell: | for i in geth.common.sh geth.node.{{ node_type|quote }}.sh ; do wget -q -O ~/env/${i} https://raw.githubusercontent.com/alejandroalffer/alastria-node-t/master/alastria-node-data/env/${i} done + args: + executable: /bin/bash - name: Prepare geth and launch node shell: | source ~/env/geth.common.sh source ~/env/geth.node.{{ node_type|quote }}.sh - nohup /usr/local/bin/geth --datadir ~/data ${GLOBAL_ARGS} ${NETSTATS_METRICS} ${INFLUX_METRICS} ${NODE_ARGS} ${LOCAL_ARGS} & + screen -d -m -L -Logfile ~/geth.log /usr/local/bin/geth --datadir ~/data ${GLOBAL_ARGS} ${NETSTATS_METRICS} ${INFLUX_METRICS} ${NODE_ARGS} ${LOCAL_ARGS} + args: + executable: /bin/bash environment: PRIVATE_CONFIG: ignore NODE_NAME: "REG_{{ company_name|quote }}_T_{{ cpu_number|quote }}_{{ ram_number|quote }}_{{ sequential|quote }}" From f0de54c2cf1d10f533e3b833091c17b660ea8df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Wed, 14 Apr 2021 12:19:00 +0200 Subject: [PATCH 13/16] Make sure to kill geth before start the node again with new config --- ansible/deploy_regular_node.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index 896d54f..beb9548 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -156,7 +156,8 @@ shell: | source ~/env/geth.common.sh source ~/env/geth.node.{{ node_type|quote }}.sh - + + pkill geth screen -d -m -L -Logfile ~/geth.log /usr/local/bin/geth --datadir ~/data ${GLOBAL_ARGS} ${NETSTATS_METRICS} ${INFLUX_METRICS} ${NODE_ARGS} ${LOCAL_ARGS} args: executable: /bin/bash From f80d62e208b139ae11298849e4f40c6c4e6a44aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Wed, 14 Apr 2021 12:43:27 +0200 Subject: [PATCH 14/16] Improve playbook envars names and fix the crash when the node is already running and the playbook is executed --- ansible/deploy_regular_node.yml | 9 +++++---- ansible/deploy_regular_node_docker.yml | 2 +- ansible/group_vars/regular_nodes | 7 +++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index beb9548..0f7a9a2 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -94,11 +94,13 @@ - name: Download genesis.json get_url: - url: "https://raw.githubusercontent.com/alastria/alastria-node/{{ node_branch|quote }}/data/genesis.json" + url: "https://raw.githubusercontent.com/alastria/alastria-node/{{ project_repo_branch|quote }}/data/genesis.json" dest: ~/genesis.json - name: Execute geth init command - shell: /usr/local/bin/geth --datadir ~/data init ~/genesis.json + shell: | + pkill geth + /usr/local/bin/geth --datadir ~/data init ~/genesis.json - name: Mark the node as initialized shell: /bin/echo "INITIALIZED" > ~/data/INITIALIZED @@ -119,7 +121,7 @@ - name: Get current nodes and parse databases shell: | for i in boot-nodes.json validator-nodes.json regular-nodes.json ; do - wget -q -O ~/env/${i} https://raw.githubusercontent.com/alastria/alastria-node/{{ node_branch|quote }}/data/${i} + wget -q -O ~/env/${i} https://raw.githubusercontent.com/alastria/alastria-node/{{ project_repo_branch|quote }}/data/${i} done case {{ node_type|quote }} in @@ -157,7 +159,6 @@ source ~/env/geth.common.sh source ~/env/geth.node.{{ node_type|quote }}.sh - pkill geth screen -d -m -L -Logfile ~/geth.log /usr/local/bin/geth --datadir ~/data ${GLOBAL_ARGS} ${NETSTATS_METRICS} ${INFLUX_METRICS} ${NODE_ARGS} ${LOCAL_ARGS} args: executable: /bin/bash diff --git a/ansible/deploy_regular_node_docker.yml b/ansible/deploy_regular_node_docker.yml index 3b9836e..5ab2932 100644 --- a/ansible/deploy_regular_node_docker.yml +++ b/ansible/deploy_regular_node_docker.yml @@ -21,7 +21,7 @@ git: repo: '{{ project_repo }}' dest: '{{ project_path }}' - version: '{{ project_repo_version }}' + version: '{{ project_repo_branch }}' force: yes accept_hostkey: yes diff --git a/ansible/group_vars/regular_nodes b/ansible/group_vars/regular_nodes index 444f2d4..82ed183 100644 --- a/ansible/group_vars/regular_nodes +++ b/ansible/group_vars/regular_nodes @@ -10,21 +10,20 @@ company_name: cpu_number: ram_number: sequential: +project_repo_branch: testnet2 -# Variables for deploy_regular_node_docker +# Variables for only deploy_regular_node_docker project_path: /home/{{ deploy_user }}/alastria-node project_repo: https://github.com/alastria/alastria-node -project_repo_version: main enable_constellation: enable_monitor: no_launch_confirm: extra_docker_arguments: -# Variables for deploy_regular_node +# Variables for only deploy_regular_node golang_version: go1.9.5.linux-amd64.tar.gz quorum_version: v2.2.3 -node_branch: main node_type: general From 145a4b5b041400d1eabedb787cfcaa08c8ee1330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Wed, 14 Apr 2021 13:50:40 +0200 Subject: [PATCH 15/16] Remove duplicate deps --- ansible/deploy_regular_node.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index 0f7a9a2..cf2146f 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -35,9 +35,7 @@ - sysvbanner - psmisc - libleveldb-dev - - libsodium-dev - libdb5.3-dev - - dnsutils - screen state: latest From 23d8a3389d5c21a6b4d30b0774bcbf87480c97b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel?= <33127189+anthares101@users.noreply.github.com> Date: Thu, 15 Apr 2021 12:04:34 +0200 Subject: [PATCH 16/16] Configure logrotate to manage the geth logs --- ansible/deploy_regular_node.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ansible/deploy_regular_node.yml b/ansible/deploy_regular_node.yml index cf2146f..84d9bc2 100644 --- a/ansible/deploy_regular_node.yml +++ b/ansible/deploy_regular_node.yml @@ -37,6 +37,7 @@ - libleveldb-dev - libdb5.3-dev - screen + - logrotate state: latest - name: Install Golang compiler @@ -163,3 +164,19 @@ environment: PRIVATE_CONFIG: ignore NODE_NAME: "REG_{{ company_name|quote }}_T_{{ cpu_number|quote }}_{{ ram_number|quote }}_{{ sequential|quote }}" + - name: Add geth logs to logrotate + become: yes + blockinfile: + path: /etc/logrotate.d/geth + block: | + /home/{{ deploy_user }}/geth.log { + weekly + rotate 3 + size 10M + compress + missingok + notifempty + delaycompress + create 0640 {{ deploy_user }} {{ deploy_user }} + } + create: true