agent-window 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -100,12 +100,39 @@ function parseEnv(env) {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* Check if PM2 daemon is running
|
|
104
|
+
*/
|
|
105
|
+
async function isDaemonRunning(options = {}) {
|
|
106
|
+
try {
|
|
107
|
+
// Try to get PM2 version - if daemon exists, this will work
|
|
108
|
+
await execPM2Command(['--version'], { ...options, silent: true, timeout: 3000 });
|
|
109
|
+
return true;
|
|
110
|
+
} catch {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Get list of PM2 processes with auto-resurrect on empty list
|
|
104
117
|
*/
|
|
105
118
|
async function list(options = {}) {
|
|
106
119
|
try {
|
|
107
120
|
const result = await execPM2Command(['jlist'], { ...options, silent: true });
|
|
108
|
-
|
|
121
|
+
let processes = JSON.parse(result.stdout || '[]');
|
|
122
|
+
|
|
123
|
+
// If list is empty but daemon is running, try resurrect
|
|
124
|
+
// This handles the case where PM2 daemon is running but dump file is out of sync
|
|
125
|
+
if (processes.length === 0 && await isDaemonRunning(options)) {
|
|
126
|
+
try {
|
|
127
|
+
await execPM2Command(['resurrect'], { ...options, silent: true, timeout: 5000 });
|
|
128
|
+
// Retry getting the list after resurrect
|
|
129
|
+
const retryResult = await execPM2Command(['jlist'], { ...options, silent: true });
|
|
130
|
+
processes = JSON.parse(retryResult.stdout || '[]');
|
|
131
|
+
} catch {
|
|
132
|
+
// Resurrect failed, continue with empty list
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
109
136
|
return processes.map(p => {
|
|
110
137
|
const env = parseEnv(p.pm2_env?.env);
|
|
111
138
|
return {
|