Fix PM2 cluster mode and user permission errors
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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');
|
||||
}
|
||||
});
|
@@ -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/*
|
||||
|
@@ -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',
|
||||
|
Reference in New Issue
Block a user