Community guide
PM2 Process Persistence for WhatsApp Gateway Bot
How to configure PM2 to keep the OpenClaw WhatsApp session alive, handle runtime crashes, and sync server reboots on Ubuntu.
[!NOTE] ClawReady.in is an independent educational resource and setup service. It is not affiliated with, endorsed by, or operated by OpenClaw.
When running a WhatsApp automation bot via OpenClaw, any crash or server reboot will stop your bot. This guide outlines how I configured PM2 on Ubuntu to keep the processes running continuously in the background.
1. Installing PM2 Globally
First, ensure you have Node.js and NPM configured. Install PM2 globally:
sudo npm install pm2 -g
2. Setting Up the Gateway Daemon
Instead of launching the Gateway shell script manually, we can define a PM2 configuration ecosystem file (ecosystem.config.cjs) inside /opt/openclaw:
module.exports = {
apps: [
{
name: 'openclaw-gateway',
script: 'npm',
args: 'run start',
cwd: '/opt/openclaw',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '800M',
env: {
NODE_ENV: 'production',
PORT: '18789',
HOST: '127.0.0.1' // Bind to localhost only!
}
}
]
};
[!WARNING] Port Warning: Ensure the
HOSTenv parameter is set to127.0.0.1so that the Gateway process is bound strictly to the private loopback interface and not exposed to the public internet.
3. Starting the Daemon & Persistence
-
Start OpenClaw under PM2:
pm2 start ecosystem.config.cjs -
Confirm the process is online:
pm2 list -
Save the PM2 list state:
pm2 save -
Configure PM2 to start automatically on system reboot:
pm2 startupThis command will print a specific block of shell commands to copy and execute on your system. Run that printed command with root permissions (using
sudo) to register PM2 as a systemd boot service.
4. Monitoring WhatsApp Bot Health
To view the live console outputs of your WhatsApp bot and scanning events:
pm2 logs openclaw-gateway
If the WhatsApp session disconnects or the Node process crashes, PM2 will restart the worker in under a second automatically.