Skip to content

Instantly share code, notes, and snippets.

@numtel
Last active May 12, 2019 22:18
Show Gist options
  • Save numtel/96dd51106f0e7e25c50dcf4a4f119499 to your computer and use it in GitHub Desktop.
Save numtel/96dd51106f0e7e25c50dcf4a4f119499 to your computer and use it in GitHub Desktop.
Install rai_node on EC2 Ubuntu instance

Follow these instructions to start an EC2 instance running Ubuntu that will run rai_node on startup

  1. Select Ubuntu Server 16.04 LTS (HVM), SSD Volume Type. A t2.small or larger instance type is recommended.

  2. Configure the security group to match the screenshot.

  3. Download install_rai_node.sh below, update the URLs with their latest versions.

    Get latest rai_node archive URL from https://github.com/clemahieu/raiblocks/releases.

    Get latest gdrive-linux-x64 version URL from https://github.com/prasmussen/gdrive#downloads

    Find the Google Drive database snapshot mirror from the RaiBlocks subreddit wiki page

    Right click on the latest Linux archive in google drive and select "Get shareable link..."

    The id at the end of this URL should be used in the command

  4. Copy to the running instance and execute the script. You will be prompted with instructions for a Google Drive verification code.

    $ scp -i [pem identity file name] install_rai_node.sh ubuntu@[instance public ip]:~
    $ ssh -i [pem identity file name] ubuntu@[instance public ip]
    
    # In ssh session:
    $ chmod +x install_rai_node.sh
    $ ./install_rai_node.sh
  5. Test an RPC call to the node from your local machine

    curl -d '{ "action" : "block_count" }' [instance public ip]:7076
#!/bin/bash -i
DATA_PATH="/home/$USER" # Change if desired, directory must exist!
DATA_DIRECTORY="RaiBlocks" # Determined by rai_node
sudo apt update
sudo apt install -y xz-utils p7zip
cd $DATA_PATH
# Download rai_node archive
# Update this URL with the latest from:
# https://github.com/clemahieu/raiblocks/releases
curl -L https://github.com/clemahieu/raiblocks/releases/download/V9.0/rai_node.xz > rai_node.xz
# Decompress rai_node
tar xf rai_node.xz
# Download Google Drive Client
# Update this URL with the latest gdrive-linux-x64 version from:
# https://github.com/prasmussen/gdrive#downloads
wget -O gdrive https://docs.google.com/uc?id=0B3X9GlR6EmbnQ0FtZmJJUXEyRTA&export=download
# Initialize data directory by running rai_node for 5 seconds
./rai_node --daemon --data_path="$DATA_PATH/$DATA_DIRECTORY"& PID=$!; sleep 5; kill $PID
# Enable executing as application
chmod +x gdrive
# GDrive must be verified against your account for access
# An interactive prompt will ask to log in using your Google account with a special link
# The id used on this command is irrelevant and does not need to be changed.
./gdrive info 0B3X9GlR6EmbnQ0FtZmJJUXEyRTA
# Download database snapshot archive from google drive
# Update the file ID with the latest 7zip Linux database archive on Google Drive from:
# https://www.reddit.com/r/RaiBlocks/wiki/index
# Right click on the archive in google drive and select "Get shareable link..."
# The id at the end of this URL should be used in the command
./gdrive download --stdout 1JFy7OvY9bKRtQMcwczqFYdgqvOOeHqSM > db.7z
# Decompress database
p7zip -d db.7z
# Move database snapshot to data directory
mv data.ldb $DATA_PATH/$DATA_DIRECTORY/data.ldb
# replace RPC address in config.json for all interfaces
sed -i "s/\"address\": \"::1\"/\"address\": \"::ffff:0.0.0.0\"/g" "$DATA_PATH/$DATA_DIRECTORY/config.json"
# enable RPC in config.json
sed -i "s/\"rpc_enable\": \"false\"/\"rpc_enable\": \"true\"/g" "$DATA_PATH/$DATA_DIRECTORY/config.json"
# Create rai_node service
sudo touch /etc/systemd/system/rai_node.service
sudo chmod 664 /etc/systemd/system/rai_node.service
echo "[Unit]
Description=RaiBlocks node service
After=network.target
[Service]
ExecStart=$DATA_PATH/rai_node --daemon --data_path=\"$DATA_PATH/$DATA_DIRECTORY\"
Restart=on-failure
User=$NAME
Group=$(id -gn)
[Install]
WantedBy=multi-user.target" | sudo tee --append /etc/systemd/system/rai_node.service
# Enable on startup
sudo systemctl enable rai_node
# Start service
sudo service rai_node start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment