Using PM2
More actions
Building a Discord/Slack bot? You should use PM2. PM2 is the easiest way to keep Node.js, Python, and other simple scripts running in the background. (If you're running a compiled backend service or something system-level, you should check out our guide on Using Systemd; it's likely a better fit!)
Note: "My-bot" is used as a filler in commands. You should change this before running commands.
1. Installation
You have root access, so I would recommend installing PM2 globally:
npm install -g pm22. Start Your Bot
Navigate to your project folder, then use the following commands to start your app, based on which language you're using.
Node.js:
pm2 start index.js --name "my-bot"Python:
pm2 start app.py --name "my-bot" --interpreter python3Bun:
pm2 start "bun run index.ts" --name "my-bot"3. Make it Survive Reboots
When you inevitably need to restart or your LXC goes down, you want your bot to come back online without having to manually start it again. Run this command to make it survive reboots:
pm2 startup && pm2 saveNow you should be good to go!
Additional/Useful Commands:
Listing all apps:
pm2 listChecking logs:
pm2 logs my-botRestarting a bot/app:
pm2 restart my-botStopping a bot/app:
pm2 stop my-botViewing logs (this command shows the last 100 lines):
pm2 logs my-bot --lines 100