Deploying Software on Linux via PM2 Guide @ Linux Guide:
Note
PM2 only works with py (Python) and js (Javascript)!
Install Node.js and NPM:
For Ubuntu/Debian-based systems:
For RPM-based systems (e.g., CentOS/RHEL): For Fedora-based systems:How to install PM2?
OR:
Starting Up:
*Ensure you are in the right directory when doing this command
You can add any of the following optional arguments to the start command:
# Specify an app name
--name <app_name>
# Watch and Restart app when files change
--watch
# Set memory threshold for app reload
--max-memory-restart <200MB>
# Specify log file
--log <log_path>
# Pass extra arguments to the script
-- arg1 arg2 arg3
# Delay between automatic restarts
--restart-delay <delay in ms>
# Prefix logs with time
--time
# Do not auto restart app
--no-autorestart
# Specify cron for forced restart
--cron <cron_pattern>
# Attach to application log
--no-daemon
Python Discord Bot Guide:
A simple guide on how to deploy a Python Discord Bot 24/7 with PM2.
- Transfer the Bot's Source Code into a new folder named
discord-bot. Use FileZilla (Use Port Number22) for file transfers between your PC/Laptop and your Bot's server.- You can overwrite files but not folders.
- Now use Putty to access your Bot's server's command line and do the rest of the steps below.
- Use Port Number
22and "SSH" as your Connection Type.
- Use Port Number
- Enable Virtual Environments and Activate it.
- First
cdto the Bot's source code's Folder. Example:cd discord-bot - Then do the following commands in the Terminal: (This is to avoid Package Installation issues and more)
python3 -m venv .venvsource .venv/bin/activate
- First
- Install all the nesccary packages. To do this please do the command below in the terminal/command-line.
- Install Node.JS
- Install PM2
- Do: Your bot should now be online. Please note PM2 will say "Online" even if your code has encountered syntax errors or etc.