Как запустить следующее. js приложение с pm2 в кластерном режиме с помощью Yarn? - PullRequest
0 голосов
/ 09 марта 2020

Я пытаюсь запустить следующее. js приложение с 2 кластерами в pm2. Поэтому сопоставил команду yarn start с pm2 start yarn -i 2 --name "frontend" -- start

Приложение запускается, а затем падает в течение секунды.

[PM2] Starting /usr/bin/yarn in cluster_mode (2 instances)
[PM2] Done.
┌─────┬─────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name        │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼─────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ frontend    │ default     │ N/A     │ cluster │ 14901    │ 0s     │ 0    │ online    │ 0%       │ 33.8mb   │ user  │ disabled │
│ 1   │ frontend    │ default     │ N/A     │ cluster │ 14908    │ 0s     │ 0    │ online    │ 0%       │ 28.8mb   │ user  │ disabled │
└─────┴─────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

Вывод файла .log

0|frontend | /usr/share/yarn/bin/yarn:2
0|frontend | argv0=$(echo "$0" | sed -e 's,\\,/,g')
0|frontend |         ^^^^
0|frontend | 
0|frontend | SyntaxError: missing ) after argument list
0|frontend |     at Module._compile (internal/modules/cjs/loader.js:895:18)
0|frontend |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
0|frontend |     at Module.load (internal/modules/cjs/loader.js:815:32)
0|frontend |     at Function.Module._load (internal/modules/cjs/loader.js:727:14)
0|frontend |     at /usr/local/lib/node_modules/pm2/lib/ProcessContainer.js:301:25
0|frontend |     at wrapper (/usr/local/lib/node_modules/pm2/node_modules/async/internal/once.js:12:16)
0|frontend |     at next (/usr/local/lib/node_modules/pm2/node_modules/async/waterfall.js:96:20)
0|frontend |     at /usr/local/lib/node_modules/pm2/node_modules/async/internal/onlyOnce.js:12:16
0|frontend |     at WriteStream.<anonymous> (/usr/local/lib/node_modules/pm2/lib/Utility.js:186:13)
0|frontend |     at WriteStream.emit (events.js:210:5)

Примечание : Запуск приложения как приложения npm работает, но в режиме форка.

Ответы [ 2 ]

1 голос
/ 10 марта 2020
module.exports = {
    apps : [
        {
            name: "project",
            script: "./server.js",
            watch: true,
            interpreter: ".npm/yarn", //absolute path to yarn ; default is node
            interpreter_args: "",
            exec_mode: "cluster",
            cwd: "", //the directory from which your app will be launched
            args: "", //string containing all arguments passed via CLI to script
            env_development: {
                "PORT": 3000,
                "NODE_ENV": "development"
            },
            env_production: {
                "PORT": 8000,
                "NODE_ENV": "production",
            }
        }
    ]
}

здесь можно увидеть любые другие параметры:

https://pm2.keymetrics.io/docs/usage/application-declaration/

0 голосов
/ 09 марта 2020

на уровне проекта создайте файл ecosystem.config.js и установите конфигурацию ниже:

module.exports = {
    apps : [
        {
            name: "sa_page_local",
            mode: "cluster",
            script: "./server.js",
            watch: true,
            env_development: {
                "PORT": 3000,
                "NODE_ENV": "development"
            },
            env_production: {
                "PORT": 8000,
                "NODE_ENV": "production",
            }
        }
    ]
}
pm2 start ecosystem.config.js --env production

pm2 start ecosystem.config.js --env development

Я не пробовал, но только на основе документации, я написал этот сценарий.

...