Skip to content

Deployment

don edited this page Oct 20, 2026 · 1 revision

Deployment with PM2

Run commands as the account that owns the bot checkout. Keep a single production bot process to avoid duplicate event handling. Complete Configuration first.

Start and save

npm install -g pm2
pm2 start ecosystem.config.cjs
pm2 save
pm2 startup

Run the privileged startup command PM2 prints. This installs a startup service for the correct account and home directory. pm2 save saves the process list restored at boot; run it again after intentional process changes. Do not save a stopped or empty process list when you want the bot restored as running.

The included configuration sets the project working directory, one process, automatic restarts, a five-second restart delay, a high consecutive-start-failure limit, a 750 MB memory restart threshold, and timestamped logs. Persistent configuration errors still need fixing; PM2 cannot make invalid credentials or unavailable services work.

Linux service recovery

On systemd Linux, find your service name with systemctl list-unit-files 'pm2-*' (for example, pm2-ubuntu). Edit it with sudo systemctl edit pm2-ubuntu and add:

[Unit]
Wants=network-online.target
After=network-online.target
StartLimitIntervalSec=0

[Service]
Restart=always
RestartSec=10
TimeoutStartSec=120

Then run:

sudo systemctl daemon-reload
sudo systemctl enable pm2-ubuntu
sudo systemctl restart pm2-ubuntu
systemctl is-active pm2-ubuntu
systemctl is-enabled pm2-ubuntu
pm2 list
pm2 logs zekbot420 --lines 50 --nostream

Substitute your actual service name. The service restarts PM2 if it exits; PM2 restores the saved bot and restarts it after crashes. Network readiness does not guarantee Discord or the database is reachable, so inspect logs if login or initialization fails. Re-run PM2's startup setup after changing the Node/PM2 installation path.

Update

Back up .env and persistent data/ privately, and inspect git status before pulling. Preserve any local modifications instead of overwriting them.

pm2 stop zekbot420
git pull --ff-only origin main
npm ci --omit=dev
node deploy-commands.js --global
pm2 restart ecosystem.config.cjs --update-env
pm2 save
pm2 logs zekbot420 --lines 50 --nostream

Confirm a fresh Discord login and check for initialization errors. A service restart tests process restoration without rebooting the whole server. For full boot verification, schedule a reboot when a short interruption is acceptable, reconnect, and repeat the service and log checks.

Clone this wiki locally