This guide provides detailed instructions for setting up, managing, and monitoring Node.js processes using PM2 and tmux. It covers installation, configuration, auto-start setup, and using tmux for persistent and enhanced monitoring. Tailored for t3rn executors.
Before setting up the executor, make sure you have the following installed:
Follow the steps below to install the required components:
-
Install Node.js:
sudo apt install nodejs
Verify the installation:
node -v
-
Install npm:
sudo apt install npm
Verify the installation:
npm -v
-
Install PM2:
npm install pm2 -g
Verify the installation:
pm2 -v
-
Install tmux:
sudo apt install tmux
Verify the installation:
tmux -v
Follow these steps to set up the executor script and manage it using PM2:
-
Open a terminal in the executor folder.
-
Create a new file, for example,
start_executor.sh
:nano start_executor.sh
-
In the script file, add the following content (Ensure you update the settings and variables according to your needs):
#!/bin/bash export NODE_ENV=testnet # Only the 'testnet' environment is available export LOG_LEVEL=debug # Logging level for outputting detailed logs for debugging and troubleshooting export LOG_PRETTY=false # It's recommended to keep this feature set to 'false' for now, as enabling it may cause unexpected behavior while it's still being refined export EXECUTOR_PROCESS_ORDERS=true # Set this to 'false' if you don't want to process orders export EXECUTOR_PROCESS_CLAIMS=true # Set this to 'false' if you don't want to process claims export EXECUTOR_MAX_L3_GAS_PRICE=000 # Update your gas max limit with the appropriate value (in Gwei). You can check the gas tracker link at the end of this page export RPC_ENDPOINTS_ARBT='0000000000000000000000000000000000000000000000000000000000000000' # Update with your Arbitrum Sepolia RPC URL export RPC_ENDPOINTS_BSSP='0000000000000000000000000000000000000000000000000000000000000000' # Update with your Base Sepolia RPC URL export RPC_ENDPOINTS_BLSS='0000000000000000000000000000000000000000000000000000000000000000' # Update with your Blast Sepolia RPC URL export RPC_ENDPOINTS_OPSP='0000000000000000000000000000000000000000000000000000000000000000' # Update with your OP Sepolia RPC URL export RPC_ENDPOINTS_L1RN='https://brn.rpc.caldera.xyz/' # L1RN RPC URL export PRIVATE_KEY_LOCAL=0000000000000000000000000000000000000000000000000000000000000000 # Update with your private key export ENABLED_NETWORKS='arbitrum-sepolia,base-sepolia,blast-sepolia,optimism-sepolia,l1rn' # Specify the networks you want to enable for processing/claiming orders export EXECUTOR_PROCESS_PENDING_ORDERS_FROM_API=false # Set to 'true' if you want to process pending orders from the API ./executor # Run the executor with the current configuration
-
OPTIONAL | Monitor logs in terminal and write to Log file simultaneously (Note that the log file size can become large, depending on the duration of your executor process):
#!/bin/bash export NODE_ENV=testnet # Only the 'testnet' environment is available export LOG_LEVEL=debug # Logging level for outputting detailed logs for debugging and troubleshooting export LOG_PRETTY=false # It's recommended to keep this feature set to 'false' for now, as enabling it may cause unexpected behavior while it's still being refined export EXECUTOR_PROCESS_ORDERS=true # Set this to 'false' if you don't want to process orders export EXECUTOR_PROCESS_CLAIMS=true # Set this to 'false' if you don't want to process claims export EXECUTOR_MAX_L3_GAS_PRICE=000 # Update your gas max limit with the appropriate value (in Gwei) export RPC_ENDPOINTS_ARBT='0000000000000000000000000000000000000000000000000000000000000000' # Update with your Arbitrum Sepolia RPC URL export RPC_ENDPOINTS_BSSP='0000000000000000000000000000000000000000000000000000000000000000' # Update with your Base Sepolia RPC URL export RPC_ENDPOINTS_BLSS='0000000000000000000000000000000000000000000000000000000000000000' # Update with your Blast Sepolia RPC URL export RPC_ENDPOINTS_OPSP='0000000000000000000000000000000000000000000000000000000000000000' # Update with your OP Sepolia RPC URL export RPC_ENDPOINTS_L1RN='https://brn.rpc.caldera.xyz/' # L1RN RPC URL export PRIVATE_KEY_LOCAL=0000000000000000000000000000000000000000000000000000000000000000 # Update with your private key export ENABLED_NETWORKS='arbitrum-sepolia,base-sepolia,blast-sepolia,optimism-sepolia,l1rn' # Specify the networks you want to enable for processing/claiming orders export EXECUTOR_PROCESS_PENDING_ORDERS_FROM_API=false # Set to 'true' if you want to process pending orders from the API LOG_FILE="$(pwd)/executor_logs_$(date +'%Y-%m-%d_%H-%M-%S').log" # Define log file location with timestamp { # Start the executor and save all the output (including errors) to a log file while also displaying it in the terminal. echo "Starting executor process at $(date)" ./executor } 2>&1 | tee -a "$LOG_FILE" # This will log output to both the terminal and a log file
-
Make the shell script executable:
sudo chmod +x start_executor.sh
-
Start the executor with PM2:
pm2 start ./start_executor.sh --name "executor-process"
You can manage the executor process using PM2 with the following commands:
-
View all running processes:
pm2 list
-
Monitor the executor process:
pm2 logs executor-process
-
Stop the executor process:
pm2 stop executor-process
-
Restart the executor process:
pm2 restart executor-process
-
Delete the executor process:
pm2 delete executor-process
To ensure the executor restarts automatically after a reboot (Make sure the PM2 executor process status is online before proceeding):
-
Generate the PM2 startup command line:
pm2 startup
-
Run the command line generated by PM2 (It might look like this):
sudo env PATH=$PATH:/usr/bin pm2 startup systemd -u $USER --hp $HOME
-
Save the PM2 process list:
pm2 save
To temporarily stop auto-starting the executor:
-
Stop the executor process:
pm2 stop executor-process
-
Remove the executor process from the saved list:
pm2 save
-
Restart auto-start:
pm2 start executor-process pm2 save
To disable the PM2 startup executor and remove saved process:
-
Disable the PM2 startup executor:
pm2 unstartup
-
Run the command line generated by PM2 (It might look like this):
sudo env PATH=$PATH:/usr/bin pm2 unstartup systemd -u $USER --hp $HOME
-
Remove the executor process from the saved list:
pm2 save --force
For executor process persistence, use tmux to run PM2 inside a session:
-
Create a new tmux session:
tmux new -s executor
-
Run PM2 inside the tmux session to start the executor process:
pm2 start ./start_executor.sh --name "executor-process"
-
After starting the executor process, detach from the tmux session:
- Press
Ctrl + b
, thend
- Press
-
To reattach to the tmux session:
tmux attach -t executor
-
Monitor the executor process with PM2 inside tmux:
pm2 logs executor-process