Skip to content

Commit

Permalink
Updating Ansible script to install Dash node.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand256 committed Jun 27, 2023
1 parent ee41c91 commit bf7ba1e
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 26 deletions.
33 changes: 33 additions & 0 deletions ansible/install-dash-node/files/dashd-service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Source: https://github.com/kxcd/Masternode-Zeus/blob/main/masternode_zeus.sh
[Unit]
Description=Dash Core Daemon
Documentation=https://dash.org
After=syslog.target network.target

[Service]
Type=forking
User={{ service_user }}
Group={{ service_user }}
ExecStart={{ dashd_dir }}/dashd

# Time that systemd gives a process to start before shooting it in the head
TimeoutStartSec=10m

# If ExecStop is not set, systemd sends a SIGTERM, which is \"okay\", just not ideal
ExecStop={{ dashd_dir }}/dash-cli stop

# Time that systemd gives a process to stop before shooting it in the head
TimeoutStopSec=300
Restart=on-failure
RestartSec=120

# Allow for three failures in five minutes before trying to spawn another instance
StartLimitInterval=300
StartLimitBurst=3

# If the OOM kills this process, systemd should restart it.
OOMPolicy=continue
PrivateTmp=true

[Install]
WantedBy=multi-user.target
109 changes: 92 additions & 17 deletions ansible/install-dash-node/install-dash-node-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,58 @@
vars:
swap_file: "/var/swapfile"
ssh_pubkeys_used: false
dash_network:

tasks:
- name: Check the OS distribution
fail:
msg: "Unsupported the OS distribution {{ ansible_distribution }} (should be Debian or Ubuntu)"
when: ansible_distribution != 'Ubuntu' and ansible_distribution != 'Debian'

- block:
- pause:
prompt: "Choose the Dash network: mainnet | testnet"
register: ret

- set_fact:
dash_network: "{{ ret.user_input }}"
when: dash_network is not defined or not dash_network

- fail:
msg: "Dash network is not valid. Should be mainnet or testnet"
when: dash_network != 'mainnet' and dash_network != 'testnet'

- block:
- pause:
prompt: "Choose the Unix user for Dash software owner"
register: ret

- set_fact:
dashuser: "{{ ret.user_input }}"
when: dashuser is not defined or not dashuser

- fail:
msg: "dashuser is not defined"
when: dashuser is not defined or not dashuser

- block:
- pause:
prompt: "Enter the password for {{ dashuser }}"
register: ret

- set_fact:
dashuser_password: "{{ ret.user_input }}"
when: dashuser_password is not defined or not dashuser_password

- block:
- pause:
prompt: "Enter additional SSH public key to add to {{ dashuser }}/.ssh/authorized_keys or Enter if none"
register: ret

- set_fact:
ssh_additional_pubkey: "{{ ret.user_input }}"
when: ssh_additional_pubkey is not defined or not ssh_additional_pubkey

- name: Update and upgrade packages
apt:
upgrade: "yes"
Expand Down Expand Up @@ -164,7 +214,6 @@
cmd: "{{ item }}"
become_user: "{{ dashuser }}"
loop:
- "curl https://keybase.io/codablock/pgp_keys.asc | gpg --import"
- "curl https://keybase.io/pasta/pgp_keys.asc | gpg --import"

- name: Create .dashcore dir
Expand Down Expand Up @@ -220,7 +269,7 @@
line: 'export PATH=$PATH:~/.dashcore'
become_user: "{{ dashuser }}"

- name: Check whether dash-cli exist
- name: Check whether dash-conf exist
stat:
path: ~/.dashcore/dash.conf
register: dash_conf_exists
Expand All @@ -231,19 +280,37 @@
random_rpc_name: "{{ lookup('password', '/dev/null chars=ascii_lowercase,digits length=20') }}"
random_rpc_pass: "{{ lookup('password', '/dev/null chars=ascii_lowercase,digits length=20') }}"

- name: Create dash.conf
- name: Create dash.conf for mainnet
copy:
dest: ~/.dashcore/dash.conf
content: |
testnet={{ "1" if dashnode_testnet else "0" }}
rpcuser=rpcuser{{ random_rpc_name }}
rpcpassword=rpcpassword{{ random_rpc_pass }}
rpcallowip=127.0.0.1
port=9999
listen=1
server=1
daemon=1
externalip={{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}
when: not dashnode_testnet
become_user: "{{ dashuser }}"

- name: Create dash.conf for testnet
copy:
dest: ~/.dashcore/dash.conf
content: |
testnet={{ "1" if dashnode_testnet else "0" }}
rpcuser=rpcuser{{ random_rpc_name }}
rpcpassword=rpcpassword{{ random_rpc_pass }}
rpcallowip=127.0.0.1
port={{ "19999" if dashnode_testnet else "9999" }}
listen=1
server=1
daemon=1
externalip={{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}
[test]
port=19999
when: dashnode_testnet
become_user: "{{ dashuser }}"
when: not dash_conf_exists.stat.exists

Expand All @@ -252,24 +319,28 @@
lineinfile:
dest: ~/.dashcore/dash.conf
line: addressindex=1
insertafter: ^rpcallowip\s*=.*
become_user: "{{ dashuser }}"

- name: Add spentindex options to dash.conf
lineinfile:
dest: ~/.dashcore/dash.conf
line: spentindex=1
insertafter: ^rpcallowip\s*=.*
become_user: "{{ dashuser }}"

- name: Add timestampindex options to dash.conf
lineinfile:
dest: ~/.dashcore/dash.conf
line: timestampindex=1
insertafter: ^rpcallowip\s*=.*
become_user: "{{ dashuser }}"

- name: Add txindex options to dash.conf
lineinfile:
dest: ~/.dashcore/dash.conf
line: txindex=1
insertafter: ^rpcallowip\s*=.*
become_user: "{{ dashuser }}"
when: enable_dashd_indexing

Expand Down Expand Up @@ -300,19 +371,23 @@
become_user: "{{ dashuser }}"
when: is_masternode

- name: Get dashd PID
shell:
cmd: pgrep dashd
register: dashd_pids
ignore_errors: true
changed_when: false
become_user: "{{ dashuser }}"

- name: Start dashd
shell:
cmd: ~/.dashcore/dashd
when: not dashd_pids.stdout
become_user: "{{ dashuser }}"
- name: Create a systemd service for dashd
template:
src: files/dashd-service.j2
dest: "/etc/systemd/system/dashd-{{ dash_network }}.service"
force: no
vars:
service_user: "{{ dashuser }}"
dashd_dir: "/home/{{ dashuser }}/.dashcore"
become: True

- name: Start dashd-{{ dash_network }} service
systemd:
state: started
enabled: true
unit: "dashd-{{ dash_network }}"
daemon_reload: yes
become: true

- name: Disable SSH root login
lineinfile:
Expand Down
13 changes: 7 additions & 6 deletions ansible/install-dash-node/install-dash-node-vars
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
dashuser: dash
dashuser_password: ""
dashnode_testnet: false
ssh_additional_pubkey: ""
dashuser:
dash_network:
dashuser_password:
dashnode_testnet: true
ssh_additional_pubkey:
ssh_disable_password_login: true
ssh_disable_root_login: true
ssh_add_local_id_rsa_pubkey: true
ssh_add_local_id_rsa_pubkey: false
enable_dashd_indexing: true
is_masternode: true
is_masternode: false
swap_size: "4G"
15 changes: 12 additions & 3 deletions doc/installing-dash-node-ansible.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,23 @@ After making changes, save them (Ctrl + O, ENTER) and exit the editor (Ctrl + X)
#### Step 3. Run the Ansible script
```
cd ~/dash-masternode-tool/ansible/install-dash-node
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook --ask-pass -i HOST_IP, -e "ansible_user=root dashuser_password=DASHUSER_PASS" install-dash-node-ubuntu.yml
ansible-playbook --ask-pass -i HOST_IP, -u root install-dash-node-ubuntu.yml
```
Replace capitalized strings with the appropriate values:
* **HOST_IP**: IP address of your VPS server on which you install Dash node
* **DASHUSER_PASS**: The password to be set for the newly created linux user who will own the Dash software (above referred to as dashuser).
At the beginning, the **SSH password** prompt will be displayed, to which you should reply by entering the password for the root user of your VPS. After that, the server configuration process will begin, the individual steps of which can be viewed on the terminal screen. It will take up to a dozen minutes and when it is finished you will see something like this:
**Note:** one of the steps in the script is to set up a Linux account with sudo privileges and prevent logins to the root account via SSH for security reasons, so if you are running the script a second time, you should modify the way you start it as follows:
```
ansible-playbook --ask-pass -i HOST_IP, -u DASHUSER_NAME -e "ansible_become_pass=DASHUSER_PASSWORD" install-dash-node-ubuntu.yml
```
Replace capitalized strings with the appropriate values:
* **DASHUSER_NAME**: the name you chose for the newly created Linux user (dash by default).
* **DASHUSER_PASSWORD**: the password you chose for the newly created Linux user.
At the beginning, the **SSH password** prompt will be displayed, to which you should reply by entering the password for the root user of your VPS. After that, the server configuration process will begin, the individual steps of which can be viewed on the terminal screen. It will take up to a dozen minutes, and when it is finished you will see something like this:
![Ansible results](img/ansible-dash-node-installation-result.png)
The outcome should be that the server has been properly configured to work as a Dash node and finally the *dashd* program has been launched, starting its synchronization with the Dash blockchain. This process will probably take up to several hours, and you can check its status by executing the `dash-cli mnsync status` command periodically.
Expand Down

0 comments on commit bf7ba1e

Please sign in to comment.