Skip to main content

Detailed Guide: Run Gunbot on a Linux VPS with PM2

· 3 min read
@boekenbox

This guide explains how to set up Gunbot—a cryptocurrency trading automation tool—on a Linux Virtual Private Server (VPS) using PM2. Running Gunbot on a VPS ensures your trading bot stays online 24/7, independent of your personal computer, minimizing the risk of downtime.

Symbol image of setting up a gunbot server

This guide explores how to run Gunbot on a budget-friendly VPS using PM2.

Benefits of PM2

PM2 is a process manager for Node.js applications that simplifies managing Gunbot:

  • Process Management: Easily start, stop, and restart Gunbot.
  • Logging and Monitoring: Automatically handles logs and simplifies log management.
  • Startup Scripts: Ensures Gunbot automatically restarts after a server reboot.

Setting Up Your VPS

Before proceeding, set up your Linux VPS following your provider's guidelines. Ubuntu is recommended for its simplicity and broad support.

Connect to your server via SSH using a tool compatible with your operating system:

Installing Gunbot and PM2

Download the latest stable Gunbot release (gunthy-linux.zip) and upload it to your VPS using your SSH client. Then, unzip it:

unzip gunthy_linux.zip

Next, install Node.js, npm, and PM2:

sudo apt update
sudo apt install nodejs npm -y
npm install pm2@latest -g

Start Gunbot using PM2 (replace myGunbotProcess with your chosen name):

pm2 start gunthy-linux --name myGunbotProcess

Configuring Firewall

Allow access to Gunbot's default port (5000) using Ubuntu's firewall (UFW):

sudo ufw allow 5000

Check your VPS provider's firewall settings if issues persist.

Managing Logs with PM2

Use PM2 commands to manage logs easily:

# View all process logs
pm2 logs

# View logs for a specific process
pm2 logs myGunbotProcess

# Clear all logs
pm2 flush

Set up automatic log rotation to prevent logs from growing too large:

pm2 install pm2-logrotate

Automatically Restarting Gunbot on System Reboot

Configure PM2 to automatically restart Gunbot after reboot:

pm2 startup
pm2 save

Updating Gunbot

To update Gunbot, follow these steps:

  1. Stop Gunbot:
pm2 stop your-process-name
  1. Upload and replace the existing gunthy-linux file.
  2. Restart Gunbot:
pm2 restart your-process-name

Always review Gunbot’s official upgrade instructions when updates are available.

Running Multiple Gunbot Instances

To run multiple Gunbot instances on a single server:

  1. Duplicate your Gunbot folder for each instance.
  2. Modify config.js in each folder to have unique settings (instructions for multiple instances):
nano config.js
  1. Start each Gunbot instance with a unique name:
pm2 start gunthy-linux --name "another-process-name"

Save your configuration for automatic restarts:

pm2 startup
pm2 save

Using Gunbot with PM2 on a Linux VPS provides a reliable, always-on environment suitable for automated cryptocurrency trading. Remember, it doesn't have to break your bank! Affordable options like Hetzner Cloud or Contabo are perfect examples of that.