From 0c602647fee89424ad9297d1586d8ead9c38b4ea Mon Sep 17 00:00:00 2001 From: M SHAH Date: Mon, 18 Nov 2024 16:31:40 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20added=20pm2=20exit=20code=20feat=20?= =?UTF-8?q?#3252?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/server.js | 2 + docs/docs/get-started/quick-run.md | 65 +++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/bin/server.js b/bin/server.js index 1e34acc535..b6a36c215c 100755 --- a/bin/server.js +++ b/bin/server.js @@ -25,6 +25,8 @@ async function start() { require.resolve(CLI), '--name', procName, + '--stop-exit-codes', + '88', ...pm2Flags, '--', ...cliFlags.filter(x=>!pm2Flags.includes(x)) diff --git a/docs/docs/get-started/quick-run.md b/docs/docs/get-started/quick-run.md index 675f9f955c..5d472c4544 100644 --- a/docs/docs/get-started/quick-run.md +++ b/docs/docs/get-started/quick-run.md @@ -70,23 +70,17 @@ You will might need to manually install **cloudflared** for this to work. ## Session Management -Starting from version 2.0.0, sessions are managed using base64 strings. You can restore a session using any of these equivalent commands: +You may want to run multiple instances of the easy api for different host accounts. To enable this you will need to ensure that each session has a unique session ID and a seperate port. ```bash # Using --session-data (recommended) -npx @open-wa/wa-automate --session-data "YOUR_BASE64_SESSION_DATA" +npx @open-wa/wa-automate --session-id sales --port 8081 # Using --session -npx @open-wa/wa-automate --session "YOUR_BASE64_SESSION_DATA" +npx @open-wa/wa-automate --session-id marketing --port 8082 -# Using -s (shorthand) -npx @open-wa/wa-automate -s "YOUR_BASE64_SESSION_DATA" ``` -:::note -Always wrap your session data string in double quotes (`""`), not single quotes. -::: - ## Server Deployment When deploying to a remote server, specify your API hostname for proper documentation: @@ -122,6 +116,59 @@ This interactive documentation includes: - Testing interface - Authentication details +## Process Management with PM2 + +Starting from V4.35.0, you can manage your EASY API process using PM2. This provides several benefits: +- Automatic session recovery after restarts +- Memory usage management +- Process monitoring and logging +- Scheduled restarts + +:::info Prerequisites +Make sure you have PM2 installed globally: +```bash +npm install -g pm2@latest +``` +::: + +### Basic PM2 Integration + +Use the `--pm2` flag to offload your process to PM2: + +```bash +npx @open-wa/wa-automate --pm2 --session-id STICKER-BOT +``` + +:::note +The process name is taken from the `--session-id` flag (default: `@OPEN-WA EASY API`). PM2 will not read the session ID from `cli.config.json`. +::: + +To use a different PM2 process name while keeping your existing session ID: + +```bash +npx @open-wa/wa-automate --pm2 --name STICKER-BOT +``` + +### Advanced PM2 Configuration + +PM2 offers powerful process management features that you can utilize: + +```bash +npx @open-wa/wa-automate --pm2 "--max-memory-restarts 300M --cron-restart=\"0 */3 * * *\" --restart-delay=3000" --name STICKER-BOT +``` + +This example: +- Restarts the process if memory exceeds 300MB +- Schedules restarts every 3 hours +- Adds a 3-second delay between restarts + +:::warning +When using PM2 flags, do not use the `=` sign between the `--pm2` flag and its value. The following will NOT work: +```bash +npx @open-wa/wa-automate --pm2="--max-memory-restarts 300M" +``` +::: + ## Getting Help View all available options and their descriptions: