В этот пост добавлена новая информация, основанная на отладке
Я пытаюсь выполнить развертывание с pm2 для сайта Gatsby JS на EC2. Раньше мне удавалось заставить Gatsby запускаться вручную на ec2 с pm2, но не с развертыванием.
Вот мой ecosystem.config.js
файл
module.exports = {
apps : [{
name: 'wispyCo',
script: 'npm',
args : 'start',
watch: '.',
env:{
NODE_ENV: "production",
MY_SANITY_TOKEN : "fdsa",
SANITY_TOKEN_WRITE : "fdsaf",
SLACK_WEBHOOK_URL : "fds"
}
},
],
deploy : {
production : {
user : 'ubuntu',
host : 'ec2-54-226-83-78.compute-1.amazonaws.com',
ref : 'origin/development',
repo : 'git@github.com:fdsafa',
path : '/home/ubuntu/wispyDeploy',
'pre-deploy-local': '',
'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production',
'pre-setup': '',
}
}
};
Вот мои скрипты для пакета. json для Gatsby
"scripts": {
"develop": "gatsby develop -H 0.0.0.0 --port 8000",
"start": "run-p start:**",
"start:app": "npm run develop",
"start:lambda": "netlify-lambda serve src/lambda",
"build": "gatsby build && netlify-lambda build src/lambda",
"build:app": "gatsby build",
"build:lambda": "netlify-lambda build src/lambda"
}
Что происходит, pm2 просто продолжает перезагружаться который выглядит примерно так.
PM2 | 2020-05-07T13:29:35: PM2 log: pid=31900 msg=process killed
PM2 | 2020-05-07T13:29:35: PM2 log: App [wispyCo:0] starting in -fork mode-
PM2 | 2020-05-07T13:29:35: PM2 log: App [wispyCo:0] online
PM2 | 2020-05-07T13:29:37: PM2 log: Change detected on path lambda/hello.js for app wispyCo - restarting
PM2 | 2020-05-07T13:29:37: PM2 log: Stopping app:wispyCo id:0
PM2 | 2020-05-07T13:29:37: PM2 log: App [wispyCo:0] exited with code [0] via signal [SIGINT]
PM2 | 2020-05-07T13:29:38: PM2 log: pid=32016 msg=process killed
PM2 | 2020-05-07T13:29:38: PM2 log: App [wispyCo:0] starting in -fork mode-
PM2 | 2020-05-07T13:29:38: PM2 log: App [wispyCo:0] online
PM2 | 2020-05-07T13:29:40: PM2 log: Change detected on path lambda/hello.js for app wispyCo - restarting
PM2 | 2020-05-07T13:29:40: PM2 log: Stopping app:wispyCo id:0
PM2 | 2020-05-07T13:29:40: PM2 log: App [wispyCo:0] exited with code [0] via signal [SIGINT]
PM2 | 2020-05-07T13:29:40: PM2 log: pid=32132 msg=process killed
PM2 | 2020-05-07T13:29:40: PM2 log: App [wispyCo:0] starting in -fork mode-
PM2 | 2020-05-07T13:29:40: PM2 log: App [wispyCo:0] online
/home/ubuntu/.pm2/logs/wispyCo-error.log last 15 lines:
/home/ubuntu/.pm2/logs/wispyCo-out.log last 15 lines:
0|wispyCo | > run-p start:**
0|wispyCo |
0|wispyCo |
0|wispyCo | > gatsby-starter-default@0.1.0 start:app /home/ubuntu/wispyDeploy/source
0|wispyCo | > npm run develop
0|wispyCo |
0|wispyCo |
0|wispyCo | > gatsby-starter-default@0.1.0 start:lambda /home/ubuntu/wispyDeploy/source
0|wispyCo | > netlify-lambda serve src/lambda
0|wispyCo |
0|wispyCo |
0|wispyCo | > gatsby-starter-default@0.1.0 develop /home/ubuntu/wispyDeploy/source
0|wispyCo | > gatsby develop -H 0.0.0.0 --port 8000
0|wispyCo |
0|wispyCo | netlify-lambda: Starting server
PM2 | Change detected on path lambda/hello.js for app wispyCo - restarting
PM2 | Stopping app:wispyCo id:0
0|wispyCo | Hash: d0c09734a446097dbcc4
0|wispyCo | Version: webpack 4.41.5
0|wispyCo | Time: 1141ms
0|wispyCo | Built at: 05/07/2020 1:29:43 PM
0|wispyCo | Asset Size Chunks Chunk Names
0|wispyCo | hello.js 131 KiB 0 [emitted] hello
0|wispyCo | slack.js 277 KiB 1 [emitted] slack
0|wispyCo | Entrypoint hello = hello.js
0|wispyCo | Entrypoint slack = slack.js
0|wispyCo | [0] /home/ubuntu/wispyDeploy/source/node_modules/object-assign/index.js 2.06 KiB {0} [built]
0|wispyCo | [2] external "stream" 42 bytes {0} {1} [built]
0|wispyCo | [3] external "url" 42 bytes {0} {1} [built]
0|wispyCo | [5] external "http" 42 bytes {0} {1} [built]
0|wispyCo | [8] external "https" 42 bytes {0} {1} [built]
0|wispyCo | [14] external "fs" 42 bytes {0} {1} [built]
0|wispyCo | [15] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/filter.js 66 bytes {0} [built]
0|wispyCo | [16] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/map.js 57 bytes {0} [built]
0|wispyCo | [18] /home/ubuntu/wispyDeploy/source/node_modules/dotenv/lib/main.js 2.93 KiB {0} {1} [built]
0|wispyCo | [19] external "path" 42 bytes {0} {1} [built]
0|wispyCo | [23] external "querystring" 42 bytes {0} {1} [built]
0|wispyCo | [58] /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js 7.93 KiB {1} [built]
0|wispyCo | [59] ./hello.js 1.79 KiB {0} [built]
0|wispyCo | [60] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/client/lib/sanityClient.js 3.43 KiB {0} [built]
0|wispyCo | [155] ./slack.js 1000 bytes {1} [built]
0|wispyCo | + 165 hidden modules
0|wispyCo | WARNING in /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/iconv-loader.js 9:12-34
0|wispyCo | Critical dependency: the request of a dependency is an expression
0|wispyCo | @ /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/encoding.js
0|wispyCo | @ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/lib/body.js
0|wispyCo | @ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js
0|wispyCo | @ ./slack.js
PM2 | App [wispyCo:0] exited with code [0] via signal [SIGINT]
PM2 | pid=32248 msg=process killed
PM2 | App [wispyCo:0] starting in -fork mode-
PM2 | App [wispyCo:0] online
0|wispyCo | > gatsby-starter-default@0.1.0 start /home/ubuntu/wispyDeploy/source
0|wispyCo | > run-p start:**
0|wispyCo | > gatsby-starter-default@0.1.0 start:lambda /home/ubuntu/wispyDeploy/source
0|wispyCo | > netlify-lambda serve src/lambda
0|wispyCo | > gatsby-starter-default@0.1.0 start:app /home/ubuntu/wispyDeploy/source
0|wispyCo | > npm run develop
0|wispyCo | > gatsby-starter-default@0.1.0 develop /home/ubuntu/wispyDeploy/source
0|wispyCo | > gatsby develop -H 0.0.0.0 --port 8000
0|wispyCo | netlify-lambda: Starting server
pm2.log выглядит следующим образом:
2020-05-07T13:31:26: PM2 log: Change detected on path lambda/hello.js for app wispyCo - restarting
2020-05-07T13:31:26: PM2 log: Stopping app:wispyCo id:0
2020-05-07T13:31:26: PM2 log: App [wispyCo:0] exited with code [0] via signal [SIGINT]
2020-05-07T13:31:26: PM2 log: pid=4137 msg=process killed
2020-05-07T13:31:26: PM2 log: App [wispyCo:0] starting in -fork mode-
2020-05-07T13:31:26: PM2 log: App [wispyCo:0] online
Это не error.log, а out.log, который выглядит следующим образом который просто перезапускает pm2
> gatsby-starter-default@0.1.0 start /home/ubuntu/wispyDeploy/source
> run-p start:**
> gatsby-starter-default@0.1.0 start:lambda /home/ubuntu/wispyDeploy/source
> netlify-lambda serve src/lambda
> gatsby-starter-default@0.1.0 start:app /home/ubuntu/wispyDeploy/source
> npm run develop
> gatsby-starter-default@0.1.0 develop /home/ubuntu/wispyDeploy/source
> gatsby develop -H 0.0.0.0 --port 8000
netlify-lambda: Starting server
Hash: d0c09734a446097dbcc4
Version: webpack 4.41.5
Time: 1117ms
Built at: 05/07/2020 1:35:58 PM
Asset Size Chunks Chunk Names
hello.js 131 KiB 0 [emitted] hello
slack.js 277 KiB 1 [emitted] slack
Entrypoint hello = hello.js
Entrypoint slack = slack.js
[0] /home/ubuntu/wispyDeploy/source/node_modules/object-assign/index.js 2.06 KiB {0} [built]
[2] external "stream" 42 bytes {0} {1} [built]
[3] external "url" 42 bytes {0} {1} [built]
[5] external "http" 42 bytes {0} {1} [built]
[8] external "https" 42 bytes {0} {1} [built]
[14] external "fs" 42 bytes {0} {1} [built]
[15] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/filter.js 66 bytes {0} [built]
[16] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/observable/operators/map.js 57 bytes {0} [built]
[18] /home/ubuntu/wispyDeploy/source/node_modules/dotenv/lib/main.js 2.93 KiB {0} {1} [built]
[19] external "path" 42 bytes {0} {1} [built]
[23] external "querystring" 42 bytes {0} {1} [built]
[58] /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js 7.93 KiB {1} [built]
[59] ./hello.js 1.79 KiB {0} [built]
[60] /home/ubuntu/wispyDeploy/source/node_modules/@sanity/client/lib/sanityClient.js 3.43 KiB {0} [built]
[155] ./slack.js 1000 bytes {1} [built]
+ 165 hidden modules
WARNING in /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/iconv-loader.js 9:12-34
Critical dependency: the request of a dependency is an expression
@ /home/ubuntu/wispyDeploy/source/node_modules/encoding/lib/encoding.js
@ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/lib/body.js
@ /home/ubuntu/wispyDeploy/source/node_modules/node-fetch/index.js
@ ./slack.js
Lambda server is listening on 9000
> gatsby-starter-default@0.1.0 start /home/ubuntu/wispyDeploy/source
> run-p start:**