Community helped me make a multi node joiner!

I have an idea about having multiple nodes from one machine without podman or docker

how to use:

tested in debian 10/11 and manjaro

a. debian: sudo apt-get update && apt-get install -y git or if you dont have sudo from root run first apt install sudo
b. manjaro sudo pacman -Syy && sudo pacman -S --noconfirm git

and now either one liner:

  1. a.
    use this one liner for dreamnet - with 20 nodes (needs ports open 12001-12020) also check if dreamnet is live at safenetforum.org or use b option

debian: git clone https://github.com/dreamerchris/dream_sn_node_joiner.git && cd dream_sn_node_joiner && sh dep_installer_debian.sh && sh multi_sn_node_joiner.sh

manjaro: git clone https://github.com/dreamerchris/dream_sn_node_joiner.git && cd dream_sn_node_joiner && sh dep_installer_manjaro.sh && sh multi_sn_node_joiner.sh

what it does is: adds dreamnet with network.config

switches to dreamnet

launches 20 nodes

the script runs vdash to see the info of your nodes with gui! ( use left/right arrows to switch node and q for exit)

and if you want to restart the nodes:

sh multi_down.sh && sh multi_sn_node_joiner.sh

or manually

  1. b.

git clone https://github.com/dreamerchris/dream_sn_node_joiner.git

then cd dream_sn_node_joiner folder

sh dep_installer_debian.sh or sh dep_installer_manjaro.sh

maybe nano multi_sn_node_joiner.sh to edit the network config or the node count etc

then run sh multi_sn_node_joiner.sh

the script runs vdash to see the info of your nodes with gui! ( use left/right arrows to switch node and q for exit)

if you want to stop all nodes run sh multi_down.sh

1 Like

What is the benefit of using a user per node, over launching multiple nodes from a single user?

1 Like

you can use the default safe node join --public-addr --local-addr --skip-auto-port-forwarding without any of the other arguments.

but I get it that it is trivial so letse make the one user multi node then

can someone tell me why the script in the for loop it doesnt replace CURRENT_NODE with the actual number in the iteration? I also get 22 12000 + {1…9} access denied and anywher that CURRENT_NODE supposed to replace with a number I get {1…9}

anyone can help me here?

multi_sn_node_joiner.sh: 22: multi_sn_node_joiner.sh: 12000+{1..9}: Permission denied
#!/bin/bash
RUST_LOG=safe_network=trace,qp2p=info   ~/.safe/node/sn_node    --max-capacity          --local-addr 192.168.2.7:      --public-addr 5.54.176.151:      --skip-auto-port-forwarding     --root_dir /home/joiner/.safe/node/local_node{1..9}/   --log-dir /home/joiner/.safe/node/local_node{1..9}/ & disown[Unit]
Description=Safe Local Node {1..9}
[Service]
User=joiner
ExecStart=/home/joiner/.safe/node/start-node{1..9}.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.targetInvalid unit name "sn_node{1..9}.service" was escaped as "sn_node\x7b1..9\x7d.service" (maybe you should use systemd-escape?)
Failed to start sn_node\x7b1..9\x7d.service: Unit sn_node\x7b1..9\x7d.service not found.
end of multi sn node joiner script

Try this:

for CURRENT_NODE in $(seq $NODE_NUM)
do
SAFE_PORT=$((12000+${CURRENT_NODE}))
...
done
3 Likes

ok thank you it got further but again in the same spot (22) it says permission denied

multi_sn_node_joiner.sh: 22: multi_sn_node_joiner.sh: 12001: Permission denied

Nice work already, @dreamerchris!

Just to share a script I made a while back for a Docker container:

set -x

signal_handler() {
  # Kill child jobs (sn_node)
  #
  # shellcheck disable=SC2046
  kill $(jobs -p)
}
trap signal_handler INT TERM

export RUST_LOG="${RUST_LOG:-safe_network=info}"

# Use a specified IP (e.g. 127.0.0.1), or get address that routes to internet.
ip="${SN_PUBLIC_IP:-$(ip route get 255.255.255.255 | sed -nEe 's/.* src (\S+) .*/\1/p')}"

node_dir="${HOME}/.safe/node"
mkdir --parents "${node_dir}"

launch_node() {
  sn_node --skip-auto-port-forwarding \
    --local-addr="0.0.0.0:$1" --public-addr="$ip:$1" \
    --log-dir "${node_dir}/$1" --root-dir "${node_dir}/$1" \
    "$2" > /dev/null &
}

echo "Launching genesis node on $ip:12000 at $node_dir/12000..."
launch_node 12000 "--first"
sleep 5

for port in $(seq 12001 12011); do
    echo "Launching node on $ip:$port at $node_dir/$port..."
    launch_node "$port" "--hard-coded-contacts=[\"$ip:12000\"]"
    sleep 1
done

# Wait for background processes.
wait

Don’t think it works anymore and launches 12 nodes, not 15 or 33 like seems the standard today. Also not sure if it requires other updates. But perhaps helpful to look at for 5 seconds and ignore… :wink:

3 Likes

I think it’s because of the space you have inserted between = sign and $ character.

Just write:

SAFE_PORT=$((12000+${CURRENT_NODE}))

I also get an error with the space (though not the same: command not found) that disappears when I remove it (but don’t ask me why).

1 Like

THANK YOU SO MUCH! It rocks now!!!

1 Like
solved

edit: ok solved it,

edit2:

I get the services running but in systemctl I see them as exited! and no logs in the folders

anyone knows why my services are all exited in the systemctl?

 sn_node1.service                                                    loaded active exited    Safe Local Node 1
  sn_node10.service                                                   loaded active exited    Safe Local Node 10
  sn_node100.service                                                  loaded active exited    Safe Local Node 100
  sn_node11.service                                                   loaded active exited    Safe Local Node 11
  sn_node12.service                                                   loaded active exited    Safe Local Node 12
  sn_node13.service                                                   loaded active exited    Safe Local Node 13
  sn_node14.service                                                   loaded active exited    Safe Local Node 14
  sn_node15.service                                                   loaded active exited    Safe Local Node 15
  sn_node16.service                                                   loaded active exited    Safe Local Node 16
  sn_node17.service                                                   loaded active exited    Safe Local Node 17
  sn_node18.service                                                   loaded active exited    Safe Local Node 18
  sn_node19.service                                                   loaded active exited    Safe Local Node 19
  sn_node2.service                                                    loaded active exited    Safe Local Node 2
  sn_node20.service                                                   loaded active exited    Safe Local Node 20

Try adding Type=forking instead of RemainAfterExit=yes (in the [Service] section)

2 Likes

ok will try! thank you again @tfa it works like a charm now! will update the github

1 Like