This script automates the process of running multiple Nexus nodes on a Linux environment, using tmux to create a new session with a window for each node. This provides an organized and efficient way to manage multiple nodes.
Before you begin, you will need to have the following installed and configured:
-
Linux Environment: A running Linux distribution (e.g., Ubuntu, Debian, CentOS).
-
Nexus Node: You must have the Nexus node software installed and configured.
-
tmux: This script requires
tmuxto be installed. You can install it on Debian-based distributions (like Ubuntu) with the following command:sudo apt update && sudo apt install tmux
- Go to the main page of this repository on GitHub.
- Click the green
<> Codebutton. - Click Download ZIP.
- Extract the ZIP file to a location of your choice on your computer.
-
Add your node commands to the
commands.txtfile. Open thecommands.txtfile and add yournexus-network startcommands. Each line in this file represents a new Nexus node that will be launched in its own terminal tab.For example:
nexus-network start --node-id "YOUR_NODE_ID_1" nexus-network start --node-id "YOUR_NODE_ID_2"Replace
"YOUR_NODE_ID_1","YOUR_NODE_ID_2", etc., with your actual Nexus node IDs. -
Open a terminal in the folder where you have the script.
-
Make the script executable:
chmod +x nexus_automation.sh
-
Run the script:
./nexus_automation.sh
The script will then read the commands from commands.txt and open a new tmux session, with each command running in a separate window (tab).
The script is designed to be interactive and user-friendly. Here's a breakdown of what it does:
-
Tmux Detection: It first checks if
tmuxis installed on your system. If not, it will provide you with the command to install it. -
User Selection: To enhance security, the script doesn't just run as the current user. Instead, it scans for all valid user accounts on the system and asks you to choose which user you'd like to run the Nexus nodes as.
-
Command File: It will ask you for the name of the file containing your Nexus commands. By default, it looks for
commands.txt. If this file doesn't exist, the script will create it for you and then exit, allowing you to add your commands before running it again. -
Execution Delay: You will be prompted to enter a delay (in seconds) that the script will wait between launching each node. This can be helpful to prevent all nodes from starting at the exact same time. The default is 3 seconds.
-
Tmux Session Management: The script creates a
tmuxsession namednexus_nodes. If a session with this name is already running, the script will attach to it and add the new nodes as new windows. This allows you to stop and start the script without losing your running nodes. -
Command Execution: For each command in your file, the script does the following:
- It cleans the command to remove any hidden Windows characters, which prevents errors if you edit the file on a Windows machine.
- It opens a new
tmuxwindow (like a tab) namednode_1,node_2, and so on. - It runs your command inside an interactive shell, which ensures that your user's
.bashrcfile is loaded correctly. This is important so that thenexus-networkcommand can be found. - The
exec bashcommand keeps the window open after your Nexus node command finishes, so you can see any output or errors.
-
Attach Instructions: Once all commands have been launched, the script will print a final message telling you exactly how to attach to your
tmuxsession to view and interact with your running nodes.
tmux uses a prefix key combination, which is Ctrl+B by default. To issue a command, you press the prefix and then the command key.
Here are some essential shortcuts to get you started:
Ctrl+Bd: Detach from the current session (the nodes will keep running in the background).tmux attach: Re-attach to the last session.Ctrl+Bc: Create a new window (tab).Ctrl+Bn: Move to the next window.Ctrl+Bp: Move to the previous window.Ctrl+B&: Close the current window.Ctrl+B?: View all keybindings.