Skip to content

Commit 0c60264

Browse files
committed
✨ added pm2 exit code feat #3252
1 parent 6e95e9d commit 0c60264

2 files changed

Lines changed: 58 additions & 9 deletions

File tree

bin/server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ async function start() {
2525
require.resolve(CLI),
2626
'--name',
2727
procName,
28+
'--stop-exit-codes',
29+
'88',
2830
...pm2Flags,
2931
'--',
3032
...cliFlags.filter(x=>!pm2Flags.includes(x))

docs/docs/get-started/quick-run.md

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,17 @@ You will might need to manually install **cloudflared** for this to work.
7070

7171
## Session Management
7272

73-
Starting from version 2.0.0, sessions are managed using base64 strings. You can restore a session using any of these equivalent commands:
73+
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.
7474

7575
```bash
7676
# Using --session-data (recommended)
77-
npx @open-wa/wa-automate --session-data "YOUR_BASE64_SESSION_DATA"
77+
npx @open-wa/wa-automate --session-id sales --port 8081
7878

7979
# Using --session
80-
npx @open-wa/wa-automate --session "YOUR_BASE64_SESSION_DATA"
80+
npx @open-wa/wa-automate --session-id marketing --port 8082
8181

82-
# Using -s (shorthand)
83-
npx @open-wa/wa-automate -s "YOUR_BASE64_SESSION_DATA"
8482
```
8583

86-
:::note
87-
Always wrap your session data string in double quotes (`""`), not single quotes.
88-
:::
89-
9084
## Server Deployment
9185

9286
When deploying to a remote server, specify your API hostname for proper documentation:
@@ -122,6 +116,59 @@ This interactive documentation includes:
122116
- Testing interface
123117
- Authentication details
124118

119+
## Process Management with PM2
120+
121+
Starting from V4.35.0, you can manage your EASY API process using PM2. This provides several benefits:
122+
- Automatic session recovery after restarts
123+
- Memory usage management
124+
- Process monitoring and logging
125+
- Scheduled restarts
126+
127+
:::info Prerequisites
128+
Make sure you have PM2 installed globally:
129+
```bash
130+
npm install -g pm2@latest
131+
```
132+
:::
133+
134+
### Basic PM2 Integration
135+
136+
Use the `--pm2` flag to offload your process to PM2:
137+
138+
```bash
139+
npx @open-wa/wa-automate --pm2 --session-id STICKER-BOT
140+
```
141+
142+
:::note
143+
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`.
144+
:::
145+
146+
To use a different PM2 process name while keeping your existing session ID:
147+
148+
```bash
149+
npx @open-wa/wa-automate --pm2 --name STICKER-BOT
150+
```
151+
152+
### Advanced PM2 Configuration
153+
154+
PM2 offers powerful process management features that you can utilize:
155+
156+
```bash
157+
npx @open-wa/wa-automate --pm2 "--max-memory-restarts 300M --cron-restart=\"0 */3 * * *\" --restart-delay=3000" --name STICKER-BOT
158+
```
159+
160+
This example:
161+
- Restarts the process if memory exceeds 300MB
162+
- Schedules restarts every 3 hours
163+
- Adds a 3-second delay between restarts
164+
165+
:::warning
166+
When using PM2 flags, do not use the `=` sign between the `--pm2` flag and its value. The following will NOT work:
167+
```bash
168+
npx @open-wa/wa-automate --pm2="--max-memory-restarts 300M"
169+
```
170+
:::
171+
125172
## Getting Help
126173

127174
View all available options and their descriptions:

0 commit comments

Comments
 (0)