From 68ef106277736caef04b97fa6613396d964f17a6 Mon Sep 17 00:00:00 2001 From: jknapp Date: Thu, 24 Jul 2025 09:53:01 -0700 Subject: [PATCH] Fix PM2 cluster mode and user permission errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Force PM2 to use fork mode instead of cluster mode - Disable wait_ready to avoid startup issues - Add PM2 ready signal to simple-website server - Add PM2 status check after startup - Set NODE_ENV=production for PM2 startup The cluster mode was causing the UID 1002 error. Fork mode runs the process directly as the specified user without additional permission complications. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- examples/simple-website/server.js | 4 ++++ scripts/entrypoint.sh | 10 +++++++++- scripts/generate-ecosystem-config.sh | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/examples/simple-website/server.js b/examples/simple-website/server.js index ec50ae9..63ce1b1 100644 --- a/examples/simple-website/server.js +++ b/examples/simple-website/server.js @@ -26,4 +26,8 @@ app.get('/ping', (req, res) => { app.listen(port, () => { console.log(`Simple website running on port ${port}`); + // Send ready signal to PM2 + if (process.send) { + process.send('ready'); + } }); \ No newline at end of file diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index cf9b6a5..d2baea9 100755 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -91,7 +91,15 @@ fi # Start PM2 as the user with HOME environment set echo "Starting PM2 as user $user..." -su -c "cd /home/$user/app && HOME=/home/$user pm2 start ecosystem.config.js --no-daemon" $user & +cd /home/$user/app +su -c "HOME=/home/$user NODE_ENV=production pm2 start ecosystem.config.js --no-daemon" $user & + +# Give PM2 time to start +sleep 5 + +# Check if the app is running +echo "Checking PM2 status..." +su -c "pm2 status" $user # Follow logs tail -f /home/$user/logs/nginx/* /home/$user/logs/nodejs/* diff --git a/scripts/generate-ecosystem-config.sh b/scripts/generate-ecosystem-config.sh index bac907d..cce069b 100755 --- a/scripts/generate-ecosystem-config.sh +++ b/scripts/generate-ecosystem-config.sh @@ -41,12 +41,13 @@ module.exports = { apps: [{ name: '${app_name}', script: '${script_file}', + exec_mode: 'fork', instances: 1, autorestart: true, watch: false, max_memory_restart: '256M', kill_timeout: 3000, - wait_ready: true, + wait_ready: false, listen_timeout: 3000, env: { NODE_ENV: 'development',