I am planning to run and manage nodes on Linux using short scripts. I want to keep things flexible, modular, transparent and to have maximum control. At least initially. I will consider GUIs, TUIs, managers and launchers later.
Perhaps this topic can serve as a place to collect and share scripts, or links to scripts elsewhere on this forum, so that we don’t need to reinvent the wheel and to help inspiring better scripts.
Edit: Now a Wiki: We can add quick links to scripts arranged by purpose:
Launch nodes at designated port numbers
Rocky Linux 9.4, bash
Runs each node process in its own “screen.” List screens with screens -ls. (Enter screen with -r and exit pressing Ctrl-a d.) An alternative is commented-out in the script. Replace with server’s local IP address.
for (( c=53300; c<=53349; c++ ))
do
#safenode --ip=<IP> --port $c --max_log_files=10 --max_archived_log_files=0 2>&1 > /dev/null & disown
screen -LdmS "safenode$c" safenode --ip=<IP> --port $c --max_log_files=10 --max_archived_log_files=0
echo "starting node on next port following $c with 360 second delay..."
sleep 360
done
Restart node ids as needed at original port (requires original PORT number recorded in file ~/.local/share/safe/node/$i/PORT)
Rocky Linux 9.4, bash
Runs each node process in its own “screen.” List screens with screens -ls. (Enter screen with -r and exit pressing Ctrl-a d.)
for i in $(ls ~/.local/share/safe/node/)
do
iPID=$(lsof ~/.local/share/safe/node/$i/logs/safenode.log | grep "safenode " | grep -o "[0-9]*" | head -1)
iPORT=$(cat ~/.local/share/safe/node/$i/PORT)
if [[ ! $iPID -gt 0 ]]; then # continue if there is an active PID
if [[ $iPORT -gt 0 ]]; then # continue if a record of original port number is available
echo "starting node peer-id $i at port $iPORT"
screen -LdmS "safenode$iPORT" safenode --port $iPORT --root-dir ~/.local/share/safe/node/$i --log-output-dest ~/.local/share/safe/node/$i/logs --max_log_files=10 --max_archived_log_files=0
sleep 360
fi
else
echo "Skipping start of safenode$iPORT (node id $i) due to existing process $iPID or non-existent PORT record."
fi
done
Variant limiting restarts to a port range:
MINPORT=30900
MAXPORT=30999
for i in $(ls ~/.local/share/safe/node/)
do
iPID=$(lsof ~/.local/share/safe/node/$i/logs/safenode.log | grep "safenode " | grep -o "[0-9]*" | head -1)
iPORT=$(cat ~/.local/share/safe/node/$i/PORT)
if [[ ! $iPID -gt 0 ]]; then # continue if there is an active PID
if [[ $iPORT -gt 0 ]]; then # continue if a record of original port number is available
if [[ $iPORT -le $MAXPORT && $iPORT -ge $MINPORT ]]; then
echo "starting node peer-id $i at port $iPORT"
screen -LdmS "safenode$iPORT" safenode --port $iPORT --root-dir ~/.local/share/safe/node/$i --log-output-dest ~/.local/share/safe/node/$i/logs --max_log_files=10 --max_archived_log_files=0
sleep 20
fi
fi
else
echo "Skipping start of safenode$iPORT (node id $i) due to existing process $iPID or non-existent PORT record."
fi
done
Anonymize own IP address from your logs before sharing
Rocky Linux 9.4, bash
Warning: This irreversibly changes all logs. It may be better to do this on a copy. The example below assumes your public IP is 51.222.110.119
cd ~/.local
find . -type f -exec sed -i 's/51.222.110.119/99.999.999.999/g' {} +
It’s a personal preference, maybe because I don’t have enough time to try out new tools. I feel I need quick-and-dirty, simple but flexible, easy-to-understand tools. Additional layers of abstraction introduce unknowns, reduce control and increase dependency on others and the level of testing done, and generally, I try to avoid adding dependencies, using frameworks and other technology layers until I really can’t avoid it.
However, I may have to switch to using node manager in the future, for more complex operations such as upgrading nodes with minimal downtime, or some other approach for migrating nodes between systems for example (if that even makes sense vs. deletion and starting a new node).
You might want to include setting the RPC port because you can then easily run scripts doing RPC calls to find info directly from the node, like balances & status
There is a curl like project for doing rpc calls. grpcurl on github
Thanks It’s joint effort between myself and @Josh.
If you try it out it needs the nodes started with node manager to use the status command for stats and the nodes storing logs in the node manager location for greping errors.
If you have enough forum clout you can click the “…” under the topic to expand the options and then click the spanner. If you don’t, ping a mod to do it for you.
It can’t start nodes with --upnp flag. The next release can, I guess, but right now I’d like to have a script that starts nodes with configurable delay with --upnp flag. Anyone?