Launching Cardano Relay Node

Previously we launched the node in active ssh session, which means, as soon we close the browser, the node will stop working

there are 2 ways you can launch your node:

  1. launching as a script using tmux (recommended only for testnet or for any other non-production server )

  2. launching as a system service (RECOMENDED on production servers)

Launching as Systemd Service
Launching as a script
Launching as Systemd Service

create a systemd service configuration file with all the keys and other settings, so the cardano node process will be running in the background:

cat <<EOF | sudo tee -a /etc/systemd/system/cardano-node.service
[Unit]
Description=Cardano Pool
After=multi-user.target
[Service]
Type=simple
ExecStart=/home/cardano/.local/bin/cardano-node run --config /home/cardano/cnode/config/mainnet-config.json --topology /home/cardano/cnode/config/mainnet-topology.json --database-path /home/cardano/cnode/db/ --socket-path /home/cardano/cnode/sockets/node.socket --host-addr 0.0.0.0 --port 3001
KillSignal = SIGINT
RestartKillSignal = SIGINT
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=cardano
LimitNOFILE=32768
Restart=on-failure
RestartSec=15s
WorkingDirectory=~
User=cardano
Group=cardano
[Install]
WantedBy=multi-user.target
EOF

let's enable the service and start it:

sudo systemctl enable cardano-node.service
sudo systemctl start cardano-node.service

you can check the cardano nodes live logfile using journalctl

enabling service and starting the node
journalctl -u cardano-node.service -f -o cat
journal output
Launching as a script

This way to launch your cardano node is recommended ONLY for your test / non-production enviroment!

To launch node in one the window we will be using the tmux

tmux is a terminal multiplexer for Unix-like operating systems. It allows multiple terminal sessions to be accessed simultaneously in a single window. It is useful for running more than one command-line program at the same time. Here you can find keyboard shortcuts to manage tmux session https://tmuxcheatsheet.com

Let's go to our scripts folder:

cd ~/cnode/scripts/

Here are some simple scripts which we will use: 1) start_all.sh - to start all nodes 2) stop_all.sh - to stop all nodes 3) node.sh node start script (used by start_all.sh script)

you can create these scripts in your terminal or download them bellow

nano start_all.sh

#!/bin/bash

session="cardano" # Check if the session exists, discarding output # We can check $? for the exit status (zero for success, non-zero for failure)

tmux has-session -t $session 2>/dev/null if [ $? != 0 ]; then tmux attach-session -t $session tmux new -s "cardano" -n "node" -d tmux split-window -v tmux split-window -h tmux select-pane -t 'cardano:node.0' tmux split-window -h tmux send-keys -t 'cardano:node.0' './node.sh' Enter tmux send-keys -t 'cardano:node.1' 'htop' Enter tmux send-keys -t 'cardano:node.2' 'nload' Enter tmux send-keys -t 'cardano:node.3' Enter fi tmux attach-session -t $session

nano stop_all.sh

#!/bin/bash

# Check if the session exists, discarding output # We can check $? for the exit status (zero for success, non-zero for failure)

session="cardano" # Check if the session exists, discarding output # We can check $? for the exit status (zero for success, non-zero for failure) tmux has-session -t $session 2>/dev/null if [ $? != 0 ]; then echo "Session not found." else echo "Killing session" tmux kill-session -t cardano fi

nano node.sh

#!/bin/bash cardano-node run \ --database-path ~/cnode/db/ \ --socket-path ~/cnode/sockets/node.socket \ --port 3000 \ --config ~/cnode/config/mainnet-config.json \ --topology ~/cnode/config/mainnet-topology.json

Let's flag these files as executive scripts:

chmod +x start_all.sh stop_all.sh node.sh

If you want - you can also download the scripts from GitHub, but if you copied - then skip to the chmod command: https://github.com/stakepool247/CardanoHaskellTestnetScripts

cd ~/git
git clone https://github.com/stakepool247/CardanoHaskellTestnetScripts.git
cd CardanoHaskellTestnetScripts/
git checkout master

let's copy them to cardano-node script folder

cp *.sh ~/cnode/scripts/

After creating these scripts you will need to make them executable by using chmod command

cd ~/cnode/scripts/
chmod +x start_all.sh stop_all.sh node.sh

to start the node, just type the following command from your script folder:

./start_all.sh

You should see your screen similar to this, where in the first window you see the node, then in next you see the running processes and below that, you see the network traffic data. There is an "empty" window where you can run some commands when needed.

To exit the tmux session (detach) press ctrl+b and then d after pressing this the nodes will still running in the background to re-attach to the session you can run ./start_all.sh script again or type tmux a to end/kill the session - launch the ./stop_all.sh script

We have set up your first relay node!

As a next step - you can do the same for your core/relay server as you need a minimum of 2 servers

1) Relay node, a server that is between your core server and other relay servers, serves as a protection to your core 2) core node (producer): a server which is producing blocks 3) cold PC: a secure computer on which you are generating Stake Pool Keys and wallets.

Ideally, for each core server, you would have 2 relay servers where they can connect

NEVER, EVER generate your wallet and stake pool keys on your online servers! It's a BAD, BAD practice. Install on your local machine VirtualBox+Ubuntu and do the wallet and key registration (either by hand or using CNTOOLS or Martins scripts)

if you need any help - you can contact us directly using Telegram: https://t.me/StakePool247help